アプリにシンプルなボタンがあります:
<Button Content="{Binding ViewModel.Name}" Command="{Binding ViewModel.Command}" MinWidth="50">
</Button>
ボタンを右クリックすると、ボタン内のコンテンツ(テキスト)がクリップボードにコピーされます。
できますか?
前もって感謝します
アプリにシンプルなボタンがあります:
<Button Content="{Binding ViewModel.Name}" Command="{Binding ViewModel.Command}" MinWidth="50">
</Button>
ボタンを右クリックすると、ボタン内のコンテンツ(テキスト)がクリップボードにコピーされます。
できますか?
前もって感謝します
インタラクションを使用して、ボタンの MouseRightButtonUp イベントをビュー モデルのコマンドにバインドできます。あなたが見つけることができる相互作用
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseRightButtonUp">
<i:InvokeCommandAction Command="{Binding CopyButtonText}" />
</i:EventTrigger>
</i:Interaction.Triggers>
対話型名前空間をインポートする必要があります:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Window.Interactivity 名前空間には、EventTrigger と InvokeCommandAction があります。
そしてcopybuttonTestコマンドハンドラであなたができること
System.Windows.Clipboard.SetData(DataFormats.Text, Name);