This project is read-only.

Trigger Action Question

Jul 5, 2012 at 5:22 PM

Hi all.

I'm wondering if there is a way to set the TriggerActions Method Parameter to the selected item in an datagrid: eg.

<Trigger:TriggerAction TargetControl="{Binding ElementName=btnEditReminderClick}" MethodName="StartEditExisting" MethodParameter="datagrid.SelectedItem"></Trigger:TriggerAction>

Is this a possibility?

Coordinator
Jul 5, 2012 at 7:25 PM

Yes, that should work fine. The MethodParameter value is a binding expression, not a literal string. So you should be able to use element binding.

Jul 5, 2012 at 7:53 PM
Edited Jul 6, 2012 at 12:03 PM

I am quite new to WPF, could you please explain how i could achieve this? What would my MethodParameter be set to?

UPDATE:

I did some research (like i should have before asking you for the information) and found the solution:

<Trigger:TriggerAction MethodName="StartEditExisting" TargetControl="{Binding ElementName=btnEditReminderClick}" MethodParameter="{Binding ElementName=datagridList, Path=SelectedItem}"></Trigger:TriggerAction>

But now i am getting the following error:

"Target method must have 0 or 2 parameters" on TriggerActions.

 

Any suggestions?

Jul 9, 2012 at 2:41 PM

Here is an example from my code:

<ListBox 
    x:Name="ReasonList"
    Margin="5" 
    MinWidth="165" 
    ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
    ScrollViewer.VerticalScrollBarVisibility="Auto"
    HorizontalContentAlignment="Stretch"
    ItemTemplate="{StaticResource DisableItemTemplate}" 
    ItemsSource="{Binding Source={StaticResource reasonListViewSource}}" >
</ListBox>
<csla:TriggerAction 
    TargetControl="{Binding ElementName=ReasonList}" 
    MethodName="ReasonSelectionChanged" 
    TriggerEvent="SelectionChanged"
    MethodParameter="{Binding SelectedItem, ElementName=ReasonList}" />

Todd