hopefully some WPF ninja can explain to me why if I have a tab control and in my tab I put content (in this case a user control) into a ItemsControl or ContentControl the content in the contentControl will expand and fill up the whole screen but if it is in an items control it will not… I think the example will make this more clear.
public MainWindow()
{
InitializeComponent();
//This content won't expand to fill the available space
var t1 = new TabItem();
t1.Header = "Tab One";
var ic = new ItemsControl();
ic.Items.Add(new UserControl1());
t1.Content = ic;
//in this case the label will fill up the whole window...
var t2 = new TabItem();
t2.Header = "Tab Two";
var c = new ContentControl();
c.Content = new UserControl1();
t2.Content = c;
MyTab.Items.Add(t1);
MyTab.Items.Add(t2);
}
here is the XAML for the window.
<Grid>
<TabControl Name="MyTab">
</TabControl>
</Grid>
Here is the user control – nothing but a label…
<UserControl x:Class="TabControlTest.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Background="Red">
<Label Content="User control one"/>
Thanks!!!
ContentControlis intended to display a single piece of content. By default, it will stretch to fill its entire containing region, and the content within theContentControlwill stretch to fill it.ItemsControl, as suggested by the name, is meant to display multiple items within it. It will fill its containing region, but the content items added will only take up the space they require. This is because it is intended to allow more than a single item to be added – if the first item stretched to fill up the space, there would be no “room” for the other items added later.