-
Notifications
You must be signed in to change notification settings - Fork 736
/
MainWindow.xaml
40 lines (36 loc) · 2.3 KB
/
MainWindow.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<Window x:Class="UsingInvokeCommandAction.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Margin="5" FontSize="24" Foreground="DarkRed" TextWrapping="Wrap">InvokeCommandAction</TextBlock>
<TextBlock Margin="5" TextWrapping="Wrap">The <Bold>InvokeCommandAction</Bold> is useful when you need to invoke a command in response to an event raised by a control in the view.</TextBlock>
<TextBlock Margin="5" TextWrapping="Wrap">
In the following example there is a list of items and we want to execute a command in the view model when an item is selected.
The view model will then change the "Selected Item" shown below.
</TextBlock>
</StackPanel>
<ListBox Grid.Row="1" Margin="5" ItemsSource="{Binding Items}" SelectionMode="Single">
<i:Interaction.Triggers>
<!-- This event trigger will execute the action when the corresponding event is raised by the ListBox. -->
<i:EventTrigger EventName="SelectionChanged">
<!-- This action will invoke the selected command in the view model and pass the parameters of the event to it. -->
<prism:InvokeCommandAction Command="{Binding SelectedCommand}" TriggerParameterPath="AddedItems" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
<StackPanel Grid.Row="2" Margin="5" Orientation="Horizontal">
<TextBlock Foreground="DarkRed" FontWeight="Bold">Selected Item:</TextBlock>
<TextBlock AutomationProperties.AutomationId="SelectedItemTextBlock" Foreground="DarkRed" FontWeight="Bold" Margin="5,0" Text="{Binding SelectedItemText}" />
</StackPanel>
</Grid>
</Window>