C# 如何设置wpf文本框,以便在用户更改对话框大小时自动调整其大小?
如何设置wpf文本框,以便在用户更改对话框大小时自动调整其大小C# 如何设置wpf文本框,以便在用户更改对话框大小时自动调整其大小?,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" Hei
<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>
从
文本框中删除MinHeight
和MinWidth
,并将水平对齐更改为拉伸
<TextBox Margin="0,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
x:Name = "gTBxInfo"
TextWrapping="Wrap"
AcceptsReturn="True"
ScrollViewer.VerticalScrollBarVisibility="Auto" />
或者将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>
默认情况下它是拉伸的吗?@d.moncada我已经测试了您的解决方案,但是TextBox
没有填满整个区域。它只能水平调整大小,而不能vertically@rraszewski我不知道你想要它双向调整大小。我将update@d.moncada我不知道ttom的意图,但我认为当用户更改对话框大小时自动调整大小意味着在两个维度上都调整大小。@rraszewski,我解决了大小调整问题。不过,有一秒钟我还以为你是OP。最后一行定义高度的“1”是什么意思?看看这里的行/列定义,你可以使用固定大小、自动或比率因子(1*),这对我来说是新的。谢谢
<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>