mogmo .NET

C#/XAML/VB6たまにC++についてメモ程度に書いていく。あくまで自分用。責任は取れません。

MouseイベントなどをViewModelで受け取る

XAMLでインタラクションを使用する方法

以下の二つを設定します。
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"と
xmlns:core="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
Microsoft.Expression.Interactionsを参照に追加するのを忘れずに。

<Window x:Class="StandardWindow.Object.***.***"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:core="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
        xmlns:local="clr-namespace:StandardWindow.Object.DisplaySettings"
        xmlns:viewmodel="clr-namespace:***"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance {x:Type viewmodel:***}, IsDesignTimeCreatable=True}"
        Title="***" Height="450" Width="800">

        <DataGrid
                ItemsSource="{Binding Path=DisplayChannels}"
                AutoGeneratingColumn="***_AutoGeneratingColumn">
                            
                <i:Interaction.Triggers>
                        <i:EventTrigger EventName="PreviewMouseDoubleClick">
                                <core:CallMethodAction TargetObject="{Binding}" MethodName="ShowSettingsWindow"/>
                        </i:EventTrigger>
                        <i:EventTrigger EventName="PreviewKeyDown">
                                <core:CallMethodAction TargetObject="{Binding}" MethodName="KeyDownOnDataGrid"/>
                        </i:EventTrigger>
                </i:Interaction.Triggers>