我在WPF中遇到MouseBinding问题。 当我右键单击鼠标到所选项目时,表单(UserControl)打开,但所选项目丢失(取消)。
请帮帮我吗?
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");
}
}
}