c# – 当用户更改对话框的大小时,如何设置wpf文本框以自动调整大小?

前端之家收集整理的这篇文章主要介绍了c# – 当用户更改对话框的大小时,如何设置wpf文本框以自动调整大小?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
用户更改对话框的大小时,如何设置wpf文本框以自动调整大小?
<Window x:Class="MemoPad.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Background="LightGray" 
    Title="Window1" Height="350" Width="700" >
<StackPanel Orientation="Vertical">
    <Menu DockPanel.Dock ="Right">
        <MenuItem Header="Find" x:Name="gMNuFind" />
    </Menu>
    <Button Content=" Find " 
          Margin="5,10,5,5"
          x:Name="gBuFind" 
          />
    <TextBox Margin="0,0"
          HorizontalAlignment="Left"
          VerticalAlignment="Top" 
          MinHeight="270" MinWidth="690"                  
          x:Name = "gTBxInfo" 
          TextWrapping="Wrap"
          AcceptsReturn="True"
          ScrollViewer.VerticalScrollBarVisibility="Auto" 
          />
</StackPanel>

解决方法

或者将StackPanel更改为Grid
<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Background="LightGray" 
    Title="Window1" Height="350" Width="700" >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="1*" />
        </Grid.RowDefinitions>
        <Menu>
            <MenuItem Header="Find" x:Name="gMNuFind" />
        </Menu>
        <Button Grid.Row="1" Content=" Find " 
          Margin="5,5"
          x:Name="gBuFind" 
          />
        <TextBox Grid.Row="2" Margin="0,0"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch" 
          MinHeight="270" MinWidth="690"                  
          x:Name = "gTBxInfo" 
          TextWrapping="Wrap"
          AcceptsReturn="True"
          ScrollViewer.VerticalScrollBarVisibility="Auto" 
          />
    </Grid>
</Window>
原文链接:https://www.f2er.com/csharp/244804.html

猜你在找的C#相关文章