我有一个让我发疯的问题,我正在 WPF 中处理一个项目,我正在创建一个视图。
我正在设计一个包含“更多选项”部分的窗口,我什至可以让这个部分显示或隐藏。本节包含一个 tabControl,其中包含一个 TextBox,如下所示:
<TabControl Margin="10,156,12,39" Name="moreTabControl" Grid.Column="1">
<TabItem >
<Grid>
<TextBox Margin="6,6,8,28" Name="myTextBox" />
</Grid>
</TabItem>
</TabControl>
因此,在我所做的显示或隐藏“更多部分”的代码中,如下所示:
public partial class FilterView : System.Windows.Window
{
.....
// Window's height when "more" option are showed
private const int ShowMoreHeight = 386;
/// Window's height when "more" option are hidden
private const int ShowLessHeight = 186;
private bool showMore = false;
private void moreButton_Click(object sender, RoutedEventArgs e)
{
showMore = !showMore;
ResizeWindow();
}
private void ResizeWindow()
{
if (showMore)
{
moreTabControl.Visibility = System.Windows.Visibility.Visible;
moreButton.Content = "<< Less";
MinHeight = ShowMoreHeight;
Height = ShowMoreHeight;
}
else
{
moreTabControl.Visibility = System.Windows.Visibility.Collapsed;
moreButton.Content = "More >>";
MinHeight = ShowLessHeight;
Height = ShowLessHeight;
}
}
......
.....
}
一切都很顺利,直到我需要将 TextBox 更改为 RichTextBox :(,当我运行程序并按下“MoreButton”时,“more”部分按预期显示,但容器窗口向右增长了很多!
我只改变了这个:<TextBox Margin="6,6,8,28" Name="myTextBox" />
为此:<RichTextBox Margin="6,6,8,28" Name="myRichTextBox" />
有谁知道发生了什么??
先感谢您。