Reputation: 81
I'm binding WPF TabControl's ItemsSource property to an ObservableCollection of TabItem.
XAML:
<TabControl ItemsSource={Binding TabItems}/>
C#:
public ObservableCollection<TabItem> TabItems {get; set;}
With this model, the Parent property of TabItem is always null. However, If I use Items property of TabControl and add the TabItems, the parent property of TabItem in the TabControl is not null. Not sure why it is so.
Upvotes: 3
Views: 740
Reputation: 854
The parent property returns null
because the TabItem is not the child of the TabControl. One reason for this to fail is inapropriate DataContext
s, so the
XAML Code <TabControl ItemsSource={Binding TabItems}/>
could fail.
Check if the DataContexts are proper.
If you are having trouble in checking the DataContext
, try Snoop, a handy program every WPF developer must have :) Snoop
Start Snoop, ask it to 'Snoop' your running program, a window appears with Visual Hierarchy on the left. Drill down to your TabControl
and check its DataContext on the right (Its the second tab item, RightTop). Verify it shows your property you defined TabItems
(public ObservableCollection<TabItem> TabItems {get; set;}
)
Hope it helps :)
Upvotes: 1