GroupBox
は親の中にGroupBox
です。どちらも私がインナーGroupBox
を押すと、それは、独自のCommand
を発射して、親Command
もトリガされ、独自の内部グループボックスはインタラクティブ機能のイベントを受け付けません
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding ...}" />
</i:EventTrigger>
</i:Interaction.Triggers>
を持っています。
どうすればいいですか?どのように内部をGroupBox
イベントを飲み込ませるには?
<GroupBox Header="Outer" xmlns:mvvm="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding OuterCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock>...</TextBlock>
<GroupBox Header="Inner" Grid.Row="1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<mvvm:EventToCommand Command="{Binding InnerCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBlock>inner...</TextBlock>
</GroupBox>
</Grid>
</GroupBox>
public class ViewModel
{
public ViewModel()
{
OuterCommand = new RelayCommand(arg => true, (arg)=> { MessageBox.Show("outer"); });
InnerCommand = new RelayCommand(arg => true,
(arg) =>
{
MessageBox.Show("inner");
MouseButtonEventArgs mbea = arg as MouseButtonEventArgs;
if (mbea != null)
mbea.Handled = true;
});
}
public RelayCommand OuterCommand { get; }
public RelayCommand InnerCommand { get; }
}
醜いを:
これは解決策です! –
myコマンドが既にこのようになっている場合、 'new RelayCommand(this.OnInnerCommand);'を返すと、 'MouseButtonEventArgs'もどうやって渡すのですか?また、 'CanExecute'を参照している場合は、' arg => true'を2番目の位置に置くことを意味すると思います。 –
1つのコマンドだけを渡すことができるので、カスタムビヘイビアーを実装するか、内部GroupBoxのMouseLeftButtonDownイベントをビューのコードビハインドで処理してから、ビューモデルのコマンドを呼び出す必要があります。プロパティをtrueに処理します。 – mm8