Reputation: 466
I have a GroupBox
. This box contains one UserControl
<GroupBox Header="NewsBox">
<GroupBox.Content>
<NewsDay:NewsDayControl DataContext="{Binding SelectedNews}"/>
</GroupBox.Content>
</GroupBox>
Now, I want to change the Content of the GroupBox
dynamically depending on a selected Tab of a TabControl
.
<DataTrigger Binding="{Binding ElementName=TabControl, Path=SelectedIndex}" Value="0">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
This is the other UserControl
which should appear, if the Tab with Index 1 is selected:
<Imprint:ImprintControl DataContext="{Binding SelectedImprint}"/>
How can I do that?
Upvotes: 1
Views: 673
Reputation: 1670
You can use Style
with triggers like this.
<GroupBox Header="NewsBox">
<GroupBox.Style>
<Style TargetType="GroupBox">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=TabControl, Path=SelectedIndex}" Value="0">
<Setter Property="Content">
<Setter.Value>
<NewsDay:NewsDayControl DataContext="{Binding SelectedNews}"/>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=TabControl, Path=SelectedIndex}" Value="1">
<Setter Property="Content">
<Setter.Value>
<Imprint:ImprintControl DataContext="{Binding SelectedImprint}"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</GroupBox.Style>
</GroupBox>
Upvotes: 3