C
C#15mo ago
Davaaron

❔ WPF

Hi, I would like to bind some events to some relay commands that I have defined using MVVM. I have installed the nuget package for xaml behaviors but it's absolutely not triggering my command 😦
xmlns:behavior="http://schemas.microsoft.com/xaml/behaviors"
<Grid>
<TreeView ItemsSource="{Binding RootNodes}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Title}">
<behavior:Interaction.Triggers>
<behavior:EventTrigger EventName="MouseClick">
<behavior:InvokeCommandAction Command="{Binding Mode=OneWay, Path=Action}"/>
</behavior:EventTrigger>
</behavior:Interaction.Triggers>

</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
xmlns:behavior="http://schemas.microsoft.com/xaml/behaviors"
<Grid>
<TreeView ItemsSource="{Binding RootNodes}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Title}">
<behavior:Interaction.Triggers>
<behavior:EventTrigger EventName="MouseClick">
<behavior:InvokeCommandAction Command="{Binding Mode=OneWay, Path=Action}"/>
</behavior:EventTrigger>
</behavior:Interaction.Triggers>

</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
Why is my RelayCommand Action not triggered?
2 Replies
JakenVeina
JakenVeina15mo ago
step 1: check for binding errors step 2: confirm that MouseClick is the proper event
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.