テキストブロック(または場合によっては画像も-いずれにしても、そのユーザーコントロール)のダブルクリックイベントをViewModelのコマンドにバインドする必要があります。
TextBlock.InputBindingsが私のコマンドに正しくバインドされていないようです、何か助けはありますか?
テキストブロック(または場合によっては画像も-いずれにしても、そのユーザーコントロール)のダブルクリックイベントをViewModelのコマンドにバインドする必要があります。
TextBlock.InputBindingsが私のコマンドに正しくバインドされていないようです、何か助けはありますか?
<Button>
<Button.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="YourCommand" />
</Button.InputBindings>
</Button>
http://thejoyofcode.com/Invoking_a_Command_on_a_Double_Click_or_other_Mouse_Gesture.aspx
Marlon Grech の付属のコマンド動作を試してください。
簡単です。MVVM の方法を使用しましょう。ここでは、習得が容易で強力な MVVM Light を使用しています。
1. xmlns 宣言に次の行を追加します。
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;
assembly=GalaSoft.MvvmLight.Extras.WPF4"
2. テキストブロックを次のように定義します。
<textBlock text="Text with event">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<GalaSoft_MvvmLight_Command:EventToCommand
Command="{Binding Edit_Command}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</textBlock>
3.次に、ビューモデルにコマンドコードを記述します!!!
ViewModel1.cs
Public RelayCommand Edit_Command
{
get;
private set;
}
Public ViewModel1()
{
Edit_Command=new RelayCommand(()=>execute_me());
}
public void execute_me()
{
//write your code here
}
Real ERPアプリケーションで使用したので、うまくいくことを願っています
リストビューの MouseDoubleClick イベントを ViewModel のコマンドにバインドする必要があるという同様の問題もありました。
私が思いついた最も簡単な解決策は、目的のコマンド バインドを持つダミー ボタンを配置し、MouseDoubleClick イベントのイベント ハンドラーでボタンのコマンドの Execute メソッドを呼び出すことです。
.xaml
<Button Visibility="Collapsed" Name="doubleClickButton" Command="{Binding Path=CommandShowCompanyCards}"></Button>
<ListView MouseDoubleClick="ListView_MouseDoubleClick" SelectedItem="{Binding Path=SelectedCompany, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Margin="0,10,0,0" ItemsSource="{Binding Path=CompanyList, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" HorizontalContentAlignment="Stretch" >
コードビハインド
private void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
doubleClickButton.Command.Execute(null);
}
簡単ではありませんが、とてもシンプルで機能します。