いくつかのボタンを含むがあり、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。CommandParametersUserControlのコマンドごとに個別に公開できるようにしたいと思います。これは可能ですか?
将来的には、全体(基本的にはグリッド内に直接含まれるグリッド)で他のイベント(クリック、ドラッグ、データドロップ)のコマンドを公開したいと思いUserControlます。ここでも、それぞれが独自のを公開しCommandParametersます。
Commandマルチプルとペアリングについての情報があまりないCommandParameterので、間違ったアプローチを取っているのではないかと思います。CustomControlより適切でしょうか?または、これは?を使用して最もよく解決されDataTemplateますか?コマンドとしてグリッド上でクリックアンドドラッグなどのイベントを公開することも、あまりカバーされていないようです-私のニーズに合うより良いコンテナコントロールはありますか?