I have a TabControl with templated content as below:
<TabControl x:Name="Items" SelectedItem="{Binding ActiveItem}" TabStripPlacement="Left" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1">
<TabControl.ItemContainerStyle>
<!--Some style stuff-->
</TabControl.ItemContainerStyle>
<TabControl.Template>
<ControlTemplate TargetType="{x:Type TabControl}">
<!--Some structure stuff including a tabpanel and contentPresenter-->
</ControlTemplate>
</TabControl.Template>
<TabControl.ContentTemplate>
<DataTemplate>
<Button x:Name="MyButton" Visibility="{Binding x}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
The view containing this TabControl uses a ViewModel similar to this:
public class MyPageViewModel : ScreenConductorViewModelBase<IMyTab>
{
public Visibility x = Visibility.Hidden;
}
I would like the visibility of the button inside the template to pull from my parent(?) ViewModel, however its trying to retrieve x from the items viewModel.
This makes sense to me but Im not sure how to specify that this field should come from the parent instead.
I’ve tried a few things but none of them seem to work:
{Binding x}
{Binding DataContext.x}
{Binding RelativeSource={RelativeSource TemplatedParent}, Path=x}
Im sure it must be simple to do this but I cant seem to work out the binding syntax
Try