2012-09-13 10 views
10

カスタムAppBarCommandオブジェクトのコレクションを通じて宣言するAppBarボタンを表すDataTemplateがあります。DataTemplateのButton自体にWPF Button CommandParameterをバインドします。

public AppBarCommand(RelayCommand command, string buttonstyle) 
    { 
    Command = command; 
    ButtonStyle = buttonstyle; 
    } 

<DataTemplate> 
    <Button Command="{Binding Command}" 
      Style="{Binding ButtonStyle, Converter={StaticResource StringNameToStyleConverter}}"/> 
</DataTemplate> 

CommandParameterバインディングを追加したいと思いますが、パラメータはButton自体でなければなりません。これは、CallistoフライアウトのPlacementTargetを設定できるようにするためです。これは可能ですか?

+0

簡単には、ボタンのClickイベントを処理します。ハンドラで受け取る最初の引数はButtonです。 – Jay

答えて

25
<Button Command="{Binding Command}" 
     CommandParameter="{Binding RelativeSource={RelativeSource Self}}" /> 

あなたのCommandプロパティは、RelayCommandのジェネリック版である必要があります。例えばRelayCommand<object>。ミクローシュバログのような

+0

誰かが私より速い! +1 –

+0

はコンパイルできません。 – aaron

4

回答は言った、または次のことができます。

<Button x:Name="MyButton" Command="{Binding Command}" CommandParameter={Binding ElementName=MyButton ... /> 
おそらく
関連する問題