I am trying to use the mechanism of behavior, but I cannot correctly write the arguments in the method in the ViewModel . I use ListBox consisting of item including CheckBox , I actually tried various combinations of input parameters of the method, but I can’t get the Item object from ListBox when I uncheck CheckBox .
XAML
<ListBox Name="PropertiesListBox" ItemsSource="{Binding PropertiesItems}" SelectedItem="{Binding SelectedPropertyItem}"> <ListBox.ItemTemplate> <DataTemplate > <DockPanel LastChildFill="True"> <CheckBox DockPanel.Dock="Left" IsChecked="{Binding IsChecked, Mode=TwoWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="Unchecked"> <ei:CallMethodAction MethodName="PropertyUnchecked" TargetObject="{Binding}"/> </i:EventTrigger> </i:Interaction.Triggers> </CheckBox> <TextBlock DockPanel.Dock="Left" Text="{Binding Path=Item.FieldsProperty.Name}" Margin="3,0,0,0"/> <Canvas DockPanel.Dock="Right"> <Path Width="20" Height="20" Stretch="Fill" Fill="{DynamicResource CommonBorderButtonBorderMouseOnBrush}" Data="{StaticResource NextBtnGeometry}" /> </Canvas> <StackPanel/> </DockPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> C #
public void PropertyUnchecked() { MessageBox.Show("Unchecked"); } I end up with an error:
Thrown: "Could not find the method named 'PropertyChecked' on the object of type 'CheckedListItem 1' that matches the expected signature." (System.ArgumentException) Exception Message = "Could not find the method named 'PropertyChecked' on object of type 'CheckedListItem`1' that matches the expected signature.", Exception Type = "System.ArgumentException", Exception WinRT Data = null
Based on the message, I considered that the method in the ViewModel code does not have the necessary input parameters ( CheckedListItem<TProperty > exactly such items are stored in the ListBox ), I started experimenting:
[one]
public void PropertyUnchecked(CheckedListItem<TProperty>tr, object sender, RoutedEventArgs e) { MessageBox.Show("Unchecked"); } [2]
public void PropertyUnchecked(object sender, RoutedEventArgs e) { MessageBox.Show("Unchecked"); } [3]
public void PropertyUnchecked(object sender) { MessageBox.Show("Unchecked"); } Also experimented with markup:
<CheckBox DockPanel.Dock="Left" IsChecked="{Binding IsChecked, Mode=TwoWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="Unchecked"> <ei:CallMethodAction MethodName="PropertyUnchecked" TargetObject="{Binding ElementName = "PropertiesListBox", Path = "DataContex"}"/> </i:EventTrigger> </i:Interaction.Triggers> </CheckBox> With this markup, I got an empty C # method, as well as [2] and [3], however, I didn’t CheckedListItem <TProperty\> anything other than CheckBox and its properties as an item (in sender), but I need exactly the Item in which the CheckedListItem <TProperty\> object CheckedListItem <TProperty\> sits. I found how to implement something like commands with parameters, but I just need a method call , and do without commands.