1

アプリにシンプルなボタンがあります:

<Button Content="{Binding ViewModel.Name}" Command="{Binding ViewModel.Command}"  MinWidth="50">
</Button>

ボタンを右クリックすると、ボタン内のコンテンツ(テキスト)がクリップボードにコピーされます。

できますか?

前もって感謝します

4

3 に答える 3

1

インタラクションを使用して、ボタンの 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.I‌​nteractivity"

Window.Interactivity 名前空間には、EventTrigger と InvokeCommandAction があります。

そしてcopybuttonTestコマンドハンドラであなたができること

System.Windows.Clipboard.SetData(DataFormats.Text, Name);
于 2013-09-04T08:31:36.413 に答える