我在 WPF 中遇到了 MouseBinding 的问题。当我用鼠标右键单击所选项目时,表单(用户控件)打开,但所选项目丢失(取消)。
你能帮我吗?
XAML:
<UserControl.InputBindings>
<MouseBinding Gesture="RightClick" Command="{Binding ShowDWClickOnRightButton}"/>
</UserControl.InputBindings>
<DataGrid x:Name="DatagridForLogistic" Grid.Row="2" MinWidth="620" SelectionMode="Single" Margin="5"
Style="{StaticResource MujStyl}" FontStyle="Normal" FontWeight="Light"
ItemsSource="{Binding Stredisko,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding MyItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
ScrollViewer.CanContentScroll="True" HorizontalScrollBarVisibility="Visible">
命令
public ICommand ShowDWClickOnRightButton
{
get
{
return new RelayCommand(() =>
{
VMRightButton viewModel = UnityActivator.CreateInstance<VMRightButton>();
viewModel.Title = String.Format("Action on right click for card {0}", MyItem.CardId).ToString();
viewModel.NumberOfCard = MyItem.CardId;
CreateDWRightButton.Raise(new Notification() { ViewModel = viewModel });
});
}
}
属性 MyItem
public ENotifiedProperties MyItem
{
get
{
return _entityProperties;
}
set
{
if (_entityProperties != value)
{
_entityProperties = value;
NotifyPropertyChanged("MyItem");
}
}
}