I have a User Control defined like this:
XAML:
<UserControl>
<Grid x:Name="LayoutRoot">
<TabControl x:Name="TabControl" ItemsSource="{Binding Products}" >
<TabControl.ContentTemplate>
<DataTemplate>
<Grid>
<ListView ItemsSource="{Binding Features}" Name="FeaturesListView">
<ListView.View>
<GridView>
<GridViewColumn x:Name="FeatureHeader" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn x:Name="CounterHeader" DisplayMemberBinding="{Binding Counter}" />
<GridViewColumn x:Name="ExpireDateHeader" DisplayMemberBinding="{Binding ExpireDate}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
code behind:
public partial class LicenseInfoControl : UserControl
{
public LicenseInfoControl(ShowableLicense license)
{
InitializeComponent();
DataContext = license;
}
}
So, if I use one User Control for one Window:
<Window>
<Grid>
<local:LicenseInfoControl x:Name="LicenseInfoControl"/>
</Grid>
</Window>
it works great. But if I use two of them:
<Window>
<Grid>
<local:LicenseInfoControl x:Name="FileLicenseInfoControl"/>
<local:LicenseInfoControl x:Name="SamLicenseInfoControl"/>
</Grid>
</Window>
Both ListViews are empty. What am I doing wrong?
Binding worked well. The problem was that if TabControl has one TabItem – it get selected when window loaded and data exposes into it. But if TabControl has two TabItems – no one of the get selected and there’s a feeling that binding hasn’t worked. But if you select one of Tab Items – data exposes immediately.
So the decision is set SelectedIndexes at a constructor of window with two User controls (LicenseInfoControl in my case):