window resize when textbox resize

前端 未结 3 1406
心在旅途
心在旅途 2021-01-28 13:12

Here is the code for Textbox available in my window(form1.xaml),My requirement is when i am resizing my window i want to resize the textbox width also, How can i able to achieve

3条回答
  •  旧巷少年郎
    2021-01-28 14:10

    In WPF you typically place TextBox control within layout Grid control and set the ColumnDefinition Width property of that Grid cell to some relative value "*", so it will resize with the Window. Do NOT use a fixed Width="500" as per your sample: also, remove that "HorizontalAlignment="Left" (the default value is HorizontalAlignment="Stretch", so you can just omit it to simplify your XAML). See the following sample code snippet:

    
        
            
            
        
        
            
            
        
    
        
    
    

    Note: The same technique could be applied to a vertical "Height" property in case you need to make it also resizable.

    Hope this will help. Best regards,

提交回复
热议问题