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,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,10,5,5"
          x:Name="gBuFind" 
          />
        <TextBox Grid.Row="2" Margin="0,0,0,0"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch" 
          MinHeight="270" MinWidth="690"                  
          x:Name = "gTBxInfo" 
          TextWrapping="Wrap"
          AcceptsReturn="True"
          ScrollViewer.VerticalScrollBarVisibility="Auto" 
          />
    </Grid>
</Window>

关于c# - 当用户更改对话框大小时,如何设置 wpf 文本框自动调整大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28055371/

相关文章:

wpf - 并排显示的 ItemsControl DataTemplate 项目

.net - 使用 PngBitmapEncoder 的 RenderTargetBitmap 在没有显示时在虚拟机上生成空白图像,Windows 10 版本 1903

c# - WpfToolkit AutoCompleteBox 上下文菜单不工作

c# - 接口(interface)是数据类型吗?

c# - 在某些 SOAP 服务中未调用 IDispatchMessageInspector.AfterReceiveRequest

c# - 显式实现的接口(interface)中的可选参数

c# - 单击按钮(动态创建的按钮)获取对象/项目 - 堆栈面板

c# - 使用 .GetType() 可能会多次枚举 IEnumerable 警告

c# - 图片 "gradient blur"

c# - 如何覆盖样式