WPF: Manage Window Auto Height and Prevent overlapping Controls
I have this window, described below. It is essentially a touchscreen keyboard at the bottom of the window, a couple of buttons off to the right, and a 开发者_开发问答TextBox at the top that shows what is being typed. At runtime, I change the textBox.Height based on a variable (and use wrap). Up to a point (around 600), the entire window grows taller to accommodate the taller TextBox, but after that, the textBox starts to extend downward, BEHIND the keyboard control.
Two questions: 1) What keeps the window from continuing to grow taller (there is still room on the screen and in the owner window (my window is opened with ShowDialog with an owner window assigned), and 2) What causes the TextBox to start growing down and behind the other control, or rather, how do I prevent that?
<Window x:Class="WFT.Controls.TextEditDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wft="clr-namespace:WFT.Controls"
WindowStyle="None" Height="Auto" Width="Auto" WindowState="Normal"
FontSize="16pt" AllowsTransparency="True" Background="Transparent">
<wft:CaptionedBox x:Name="capBox" Caption="Edit Text" VerticalAlignment="Center" HorizontalAlignment="Center">
<DockPanel>
<DockPanel DockPanel.Dock="Right">
<wft:TouchButton DockPanel.Dock="Top" Click="Cancel_Click">Cancel</wft:TouchButton>
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" DockPanel.Dock="Right">
<wft:TouchButton x:Name="okButton" DockPanel.Dock="Bottom" Click="Login_Click">Accept</wft:TouchButton>
</StackPanel>
</DockPanel>
<wft:OnScreenKeyboard x:Name="osk" DockPanel.Dock="Bottom" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<wft:GelBox Grid.Column="0" Visibility="Hidden" />
<TextBox Name="textBox" Height="30" Grid.Column="1"
HorizontalContentAlignment="Left" DockPanel.Dock="Top"
TextWrapping="Wrap"/>
<wft:GelBox x:Name="errorIcon" Grid.Column="2" Visibility="Hidden" />
</Grid>
</DockPanel>
</wft:CaptionedBox>
</Window>
THANKS!
It appears that adding SizeToContent="WidthAndHeight"
to the Window solved both problems.
精彩评论