I have a problem that is driving me crazy, I am working on a project in WPF and I am creating a view.
I was designing a window which contains a “More Options” section, I had even been able to make this section show or hide. This section contained a tabControl which contained a TextBox as bellow:
<TabControl Margin="10,156,12,39" Name="moreTabControl" Grid.Column="1">
<TabItem >
<Grid>
<TextBox Margin="6,6,8,28" Name="myTextBox" />
</Grid>
</TabItem>
</TabControl>
So, in the code behind what I do to show or hide the “More Section” is as following:
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;
}
}
......
.....
}
Everything went well until I needed to change the TextBox for a RichTextBox :(, when I run the program and press the “MoreButton” the “more” section is showed as expected but the container window grows a lot to the right!
And I only changed this: <TextBox Margin="6,6,8,28" Name="myTextBox" /> for this: <RichTextBox Margin="6,6,8,28" Name="myRichTextBox" />
Does anyone know what is happening??
Thank you in advance.
I have solved my problem:
Turns out that in my XAML code, my Window had a property called
SizeToContentset to"WidthAndHeight", so I changed it to"Manual"and established a value forWidthandHeightmanually.Hope this helps some else who is experiencing somethig similar.