いくつかのボタンを含むがあり、UserControl
ボタンごとにCommand
DependencyProperty
定義されています。UserControl XAMLは次のとおりです(簡潔にするために一部の要素は削除されています)。
<UserControl>
<Grid>
<Button Command="{Binding CloseCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" ToolTip="Delete">
<Button Command="{Binding NavigateCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" ToolTip="Launch">
</Grid>
</UserControl>
背後にあるUserControlコードのDepencyPropertiesは次のとおりです。
public static readonly DependencyProperty CloseCommandProperty = DependencyProperty.Register("CloseCommand", typeof (ICommand), typeof (Tile));
public ICommand CloseCommand
{
get { return (ICommand)GetValue(CloseCommandProperty); }
set { SetValue(CloseCommandProperty, value); }
}
public static readonly DependencyProperty NavigateCommandProperty = DependencyProperty.Register("NavigateCommand", typeof (ICommand), typeof (Tile));
public ICommand NavigateCommand
{
get { return (ICommand) GetValue(NavigateCommandProperty); }
set { SetValue(NavigateCommandProperty, value); }
}
私はMVVMLightを使用してRelayCommands
おり、このいくつかのインスタンスを含むビューのViewModelを介してこれらのコマンドにバインドできますUserControl
。CommandParameters
UserControlのコマンドごとに個別に公開できるようにしたいと思います。これは可能ですか?
将来的には、全体(基本的にはグリッド内に直接含まれるグリッド)で他のイベント(クリック、ドラッグ、データドロップ)のコマンドを公開したいと思いUserControl
ます。ここでも、それぞれが独自のを公開しCommandParameters
ます。
Command
マルチプルとペアリングについての情報があまりないCommandParameter
ので、間違ったアプローチを取っているのではないかと思います。CustomControl
より適切でしょうか?または、これは?を使用して最もよく解決されDataTemplate
ますか?コマンドとしてグリッド上でクリックアンドドラッグなどのイベントを公開することも、あまりカバーされていないようです-私のニーズに合うより良いコンテナコントロールはありますか?