下記サイトで紹介されているプログラムをもとに、改造してみてうまく動かなかったプログラムを添付いたしました。
サイト:http://blog.basyura.org/entry/2016/03/19/235427
改造後プロジェクト一式:http://whitecats.dip.jp/up/download/156 ... 516552.rar
DLパスワード:1234
[1] 質問文
[1.1] 自分が今行いたい事は何か
サイトのプロジェクトをMVVM化したいので、まずは、UserControl(SampleControl)のコマンドをVMへ移動を計画
そこで、「RaiseSampleEvent」ボタンのClickイベントをEventToCommandを使ってVMへ記述したい
[1.2] どのように取り組んだか(プログラムコードがある場合記載)
詳しくはプロジェクト参照ください。
簡単に抜粋しました
SampleControl.xaml
<Button Grid.Row="1" Content="RaiseSampleEvent" Margin="0 10 0 0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<mvvm:EventToCommand Command="{Binding SomeCommand, Mode=TwoWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
public class MainWindowsViewModel {
public RelayCommand<RoutedEventArgs> SomeCommand { get; private set; }
public MainWindowsViewModel() {
SomeCommand = new RelayCommand<RoutedEventArgs>((param) => {
int aaa;
aaa = 1; // ここにブレイクポイントを張るが、イベントが呼ばれない
});
}
}
<Window x:Class="WPFSample_SwitchEventArgs.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WPFSample_SwitchEventArgs"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<my:MainWindowsViewModel/>
</Window.DataContext>
<Grid>
<my:SampleControl
MouseLeftButtonDown="SampleControl_MouseLeftButtonDown"
SampleChanged="SampleControl_SampleChanged"
/>
</Grid>
</Window>
[1.4] 今何がわからないのか、知りたいのか
UserControl(SampleControl)のRaiseイベントより、MainWindowViewModelのSomeCommandが動作してほしい
(現在は動作しない)
どのように実装すればよいのか?
以上になります。
お手数をおかけしますが、よろしくお願いいたします。