- darthmaule2
- Posts: 98
- Joined:
Any way to attach a command to the PreviewMouseDown event of a ListViewItem?
I have a <ListView> which I can attach a command to the PreviewMouseDown event, and that works well.
But, because it doesn't provide the EventArgs, I can't see which ListViewItem was clicked.
Is there a way to attach this same event but to the ListViewItem itself? I've tried putting it into the ControlTemplate and the Style but haven't been able to get either working.
I'm not sure how to do this in WPF either, but I've seen some work-around which I don't think can be done in Noesis.
Thanks!
But, because it doesn't provide the EventArgs, I can't see which ListViewItem was clicked.
Is there a way to attach this same event but to the ListViewItem itself? I've tried putting it into the ControlTemplate and the Style but haven't been able to get either working.
Code: Select all
<ListView
SelectionMode="Single"
Style="{StaticResource FileManagerListViewStyle}"
ItemContainerStyle="{StaticResource FileManagerListViewItemStyle}"
ItemsSource="{Binding FileManagerCollectionView.FileManagerCollectionView}">
<i:Interaction.Triggers>
<i:EventTrigger RoutedEvent="PreviewMouseDown">
<i:InvokeCommandAction Command="{Binding ListViewDownCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
...
Thanks!
-
sfernandez
Site Admin
- Posts: 2995
- Joined:
Re: Any way to attach a command to the PreviewMouseDown event of a ListViewItem?
We implemented an extension in Noesis to define interactivity triggers/behaviors in styles, and you can use that in ListViewItem style like this:
This way you will receive in the command parameter the item associated with the mouse down event. Does this work for you?
Code: Select all
<Grid
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:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">
<Grid.Resources>
<Style x:Key="FileManagerListViewItemStyle" TargetType="ListViewItem">
...
<Setter Property="noesis:StyleInteraction.Triggers">
<Setter.Value>
<noesis:StyleTriggerCollection>
<i:EventTrigger EventName="PreviewMouseDown">
<i:InvokeCommandAction
Command="{Binding DataContext.ListViewDownCommand, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
CommandParameter="{Binding}"/>
</i:EventTrigger>
</noesis:StyleTriggerCollection>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
...
</Grid>
- darthmaule2
- Posts: 98
- Joined:
Re: Any way to attach a command to the PreviewMouseDown event of a ListViewItem?
That is fantastic!... but, it looks like Noesis.GUI.Extensions requires some blend DLLs which are full .NET only right now?
Looks like Microsoft open sourced those libraries here:
https://devblogs.microsoft.com/dotnet/o ... s-for-wpf/
And this unmerged pull request adds .NET core 3.0 support:
https://github.com/microsoft/XamlBehaviorsWpf/pull/20
Think that will be cross-platform when merged or just be .NET core 3.0 on Windows only?
Looks like Microsoft open sourced those libraries here:
https://devblogs.microsoft.com/dotnet/o ... s-for-wpf/
And this unmerged pull request adds .NET core 3.0 support:
https://github.com/microsoft/XamlBehaviorsWpf/pull/20
Think that will be cross-platform when merged or just be .NET core 3.0 on Windows only?
-
sfernandez
Site Admin
- Posts: 2995
- Joined:
Re: Any way to attach a command to the PreviewMouseDown event of a ListViewItem?
Noesis.GUI.Extensions NuGet is only required for WPF Blend editing.
Those classes are already exposed in the cross-platform Noesis.App NuGet, so it will correctly work in your .NET Core 3.0 project.
Those classes are already exposed in the cross-platform Noesis.App NuGet, so it will correctly work in your .NET Core 3.0 project.
- darthmaule2
- Posts: 98
- Joined:
Re: Any way to attach a command to the PreviewMouseDown event of a ListViewItem?
Understood, thank you. I have a dozen places in the code where this would be very helpful.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 9 guests