Reputation: 1
I would like to bind a TabControl to User Controls in order to have each User Control in a TabItem.
Is this possible, knowing the TabControl is itself in a UserControl ?
Here's the Dependency Property in the UserControl :
public IList<UserControl> ListUserControls
{
get { return (IList<UserControl>)GetValue(ListUserControlsProperty); }
set { SetValue(ListUserControlsProperty, value); }
}
// Using a DependencyProperty as the backing store for ListUserControls. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ListUserControlsProperty =
DependencyProperty.Register("ListUserControls", typeof(IList<UserControl>), typeof(NavigationPane), new PropertyMetadata(new List<UserControl>()));
In the MainWindow where is the UserControl :
<pyRGC:NavigationPane.ListUserControls>
<pyRGCTest:UC_1 />
</pyRGC:NavigationPane.ListUserControls>
When I code this, it displays me : "The following type was expected : "IList'1"". I don't find how to use a IList in XAML.
How can I do ?
Thanks
Upvotes: 0
Views: 475
Reputation: 4149
Since you want to display a fixed number of tabs and you are not using MVVM
, you will have to provide TabControl
items in XAML
rather than via Binding
.
Sample code is as below:
<TabControl>
<TabControl.Items>
<TabItem Header="Tab One">
<local:UserControl1 />
</TabItem>
<TabItem Header="Tab Two">
<local:UserControl2 />
</TabItem>
</TabControl.Items>
</TabControl>
Upvotes: -1