Allow TextBox to be resized but not to grow on user input

前端 未结 3 524
挽巷
挽巷 2020-12-17 17:44

I have a TextBox defined inside a window like so:


    
             


        
3条回答
  •  清歌不尽
    2020-12-17 18:22

    The reason you're having this behavior is because you've set the Window's SizeToContent property - which basically authorizes the Window to resize itself based on the size requested by its content. So as you type in more stuff, the textbox says I need more space, the window obediently grows. Your textbox would not grow if you don't set the SizeToContent property.

    So I'd say lose the SizeToContent property setter & Use proportional grid sizing. Here I say make Column#2 twice the width of Column#1. The default "Stretch" value of HorizontalAlignment and VerticalAlignment for the Grid should ensure that your controls resize correctly on a window resize.

    
        
            
                
                
            
            
                
            
    
            Description:
            
        
    

    If you just add the SizeToContent property setter back to above code snippet... you'd see some weird behavior where the textbox initially grows with text content.. however if you resize the window once.. the textbox would stop growing. Strange... can't explain that behavior.
    HTH

提交回复
热议问题