0
我有一個令我瘋狂的問題,我正在WPF中創建一個項目,並且正在創建一個視圖。如何避免RichTextBox向右擴展
我在設計一個窗口,其中包含「更多選項」部分,我甚至可以使此部分顯示或隱藏。本節包含其中包含一個文本框爲波紋管一個TabControl:
<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;
}
}
......
.....
}
一切順利以及直到我需要改變文本框的RichTextBox :(當我運行程序並按下「MoreButton」時,「更多」部分顯示如預期,但容器窗口增長很多到正確的!
我只改變了這個:<TextBox Margin="6,6,8,28" Name="myTextBox" />
爲此:<RichTextBox Margin="6,6,8,28" Name="myRichTextBox" />
有誰知道發生了什麼?
預先感謝您。
如果我理解你的問題,你說的是當按下MoreButton窗口的高度像期望的那樣增長,但是也會增加你不想要的寬度? – Jay
@Jay完全!它確實發生了! – Dante