I have WPF window which contains Frame and two RadioButtons. I need to switch Frame's ContentTemplate by changing RadioButtons checked state. How do I implement that using only xaml?
Asked
Active
Viewed 2,167 times
1
-
every guy which follow "only xaml" idioms is looking for adventure on its ass. take it easy, and people will follow you! – stukselbax Aug 24 '11 at 07:28
-
Use Event Triggers in WPF. http://stackoverflow.com/questions/3353786/condition-in-an-eventtrigger – Mamta D Aug 24 '11 at 07:32
-
Sorry, I've forgotten to say that my Frame and RadioButtons placed in DataTemlate – lce Aug 24 '11 at 07:58
2 Answers
3
There isn't much to go on since you didn't add any sample code.. Try something like this
<ContentControl>
<ContentControl.ContentTemplate>
<DataTemplate>
<DataTemplate.Resources>
<DataTemplate x:Key="dataTemplate1">
<TextBlock Text="Template 1"/>
</DataTemplate>
<DataTemplate x:Key="dataTemplate2">
<TextBlock Text="Template 2"/>
</DataTemplate>
</DataTemplate.Resources>
<StackPanel>
<Frame x:Name="frame1"
Height="100"
ContentTemplate="{StaticResource dataTemplate1}"/>
<RadioButton x:Name="template1RadioButton" IsChecked="True" Content="Template 1"/>
<RadioButton x:Name="template2RadioButton" Content="Template 2"/>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=template2RadioButton, Path=IsChecked}" Value="True">
<Setter TargetName="frame1" Property="ContentTemplate" Value="{StaticResource dataTemplate2}"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>

Fredrik Hedblad
- 83,499
- 23
- 264
- 266