WPF DataTrigger for Navigation
-
Wednesday, January 09, 2013 7:51 PM
For the life of me I can't crack this one...in my MVVM WPF (desktop) application my window has a frame which shuffles the other pages to and fro. I would like to create an interaction data trigger which would navigate to a target page off of the frame. The trigger could be as simple as a boolean change. I haven't been able to work out that dark magic. LaunchUriOrFileAction seems like it could work....if this were Silverlight I could use the HyperlinkAction.
All Replies
-
Wednesday, January 09, 2013 9:53 PM
Hello Cheetah.
You could make use of the ChangePropertyAction in Blend.
Here is an example...
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:System="clr-namespace:System;assembly=System" x:Class="WpfApplication8.MainWindow" x:Name="Window" Title="MainWindow" Width="640" Height="480"> <Grid x:Name="LayoutRoot"> <Frame x:Name="frame" Margin="200,0,0,0" Width="400" Height="400" NavigationUIVisibility="Hidden"> <i:Interaction.Triggers> <ei:DataTrigger Binding="{Binding IsChecked, ElementName=rb1}" Value="true"> <ei:ChangePropertyAction PropertyName="Source"> <ei:ChangePropertyAction.Value> <System:Uri>Page1.xaml</System:Uri> </ei:ChangePropertyAction.Value> </ei:ChangePropertyAction> </ei:DataTrigger> <ei:DataTrigger Binding="{Binding IsChecked, ElementName=rb2}" Value="true"> <ei:ChangePropertyAction PropertyName="Source"> <ei:ChangePropertyAction.Value> <System:Uri>Page2.xaml</System:Uri> </ei:ChangePropertyAction.Value> </ei:ChangePropertyAction> </ei:DataTrigger> </i:Interaction.Triggers> </Frame> <RadioButton x:Name="rb1" Content="Go To Page 1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8,8,0,0" GroupName="a" IsChecked="True"/> <RadioButton x:Name="rb2" Content="Go To Page 2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8,27.96,0,0" GroupName="a"/> </Grid> </Window>
~Christine- Marked As Answer by CheetahChrome Wednesday, January 09, 2013 10:15 PM

