【发布时间】:2014-08-03 22:32:42
【问题描述】:
我有一个文本框,它的高度设置为Auto,允许文本换行并接受返回键。
目前,当文本框展开时,它会超出其他控件的顶部,在本例中是提交和取消按钮。我想要增长的文本框称为txtAddress,它的提交和取消按钮应该随着文本框的增长而被推开。
下面是我的 WPF
<Window x:Class="MyProject.AddContact"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Add Contact" Height="310" Width="378" WindowStartupLocation="CenterScreen">
<Grid>
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="txtName" VerticalAlignment="Top" Width="266" Foreground="#FFB3B3B3" Text="Contact Name" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" />
<Image Height="53" HorizontalAlignment="Left" Margin="284,12,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="60" Source="/BoardiesSMSServer;component/images/no-contact-image.png" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,71,0,0" Name="txtPhoneNumber" VerticalAlignment="Top" Width="170" Text="Phone Number" Foreground="#FFB3B3B3" VerticalContentAlignment="Center" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="188,71,0,0" Name="comboBox1" VerticalAlignment="Top" Width="90">
<ComboBoxItem Content="Home" IsSelected="True" />
<ComboBoxItem Content="Work" />
<ComboBoxItem Content="Work Fax" />
<ComboBoxItem Content="Home Fax" />
<ComboBoxItem Content="Pager" />
<ComboBoxItem Content="Other" />
<ComboBoxItem Content="Custom" />
<ComboBoxItem Content="Callback" />
<ComboBoxItem Content="Car" />
<ComboBoxItem Content="Company Main" />
<ComboBoxItem Content="ISDN" />
<ComboBoxItem Content="Main" />
<ComboBoxItem Content="Other Fax" />
<ComboBoxItem Content="Radio" />
<ComboBoxItem Content="Telex" />
<ComboBoxItem Content="TTY TTD" />
<ComboBoxItem Content="Work Mobile" />
<ComboBoxItem Content="Work Pager" />
<ComboBoxItem Content="Assistant" />
<ComboBoxItem Content="MMS" />
</ComboBox>
<Button Content="Submit" Height="23" HorizontalAlignment="Left" Margin="76,226,0,0" Name="btnSubmit" VerticalAlignment="Top" Width="75" Style="{StaticResource RoundCorner}" Click="btnSubmit_Click" />
<Label Content="Phone" Height="28" HorizontalAlignment="Left" Margin="12,37,0,0" Name="label3" VerticalAlignment="Top" Width="266" BorderThickness="0,0,0,1" BorderBrush="#FFA70000" Foreground="#FFA70000" FontWeight="Bold" VerticalContentAlignment="Bottom" />
<Label BorderBrush="#FFA70000" BorderThickness="0,0,0,1" Content="Email" FontWeight="Bold" Foreground="#FFA70000" Height="28" HorizontalAlignment="Left" Margin="12,100,0,0" Name="label1" VerticalAlignment="Top" VerticalContentAlignment="Bottom" Width="266" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,134,0,0" Name="txtEmail" VerticalAlignment="Top" Width="170" Foreground="#FFB3B3B3" Text="Email" />
<ComboBox Height="23" Margin="188,134,0,0" Name="comboBox2" VerticalAlignment="Top" HorizontalAlignment="Left" Width="90">
<ComboBoxItem Content="Home" IsSelected="True" />
<ComboBoxItem Content="Work" />
<ComboBoxItem Content="Other" />
<ComboBoxItem Content="Mobile" />
<ComboBoxItem Content="Custom" />
</ComboBox>
<Label BorderBrush="#FFA70000" BorderThickness="0,0,0,1" Content="Address" FontWeight="Bold" Foreground="#FFA70000" Height="28" HorizontalAlignment="Left" Margin="12,163,0,0" Name="label2" VerticalAlignment="Top" VerticalContentAlignment="Bottom" Width="266" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="188,197,0,0" Name="comboBox3" VerticalAlignment="Top" Width="90">
<ComboBoxItem Content="Home" IsSelected="True" />
<ComboBoxItem Content="Work" />
<ComboBoxItem Content="Other" />
<ComboBoxItem Content="Custom" />
</ComboBox>
<Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="157,226,0,0" Name="btnCancel" VerticalAlignment="Top" Width="75" Style="{StaticResource RoundCorner}" Click="btnCancel_Click" />
<TextBox Height="Auto" HorizontalAlignment="Left" Margin="12,197,0,0" Name="txtAddress" VerticalAlignment="Top" Width="170" TextWrapping="WrapWithOverflow" AcceptsReturn="True" MinHeight="23" Foreground="#FFB3B3B3" Text="Address" />
</Grid>
</Window>
【问题讨论】: