update
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Visible"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||
<i:Interaction.Behaviors>
|
||||
<viewmodel:StudentViewModel MouseDownCommand="{Binding MouseDownCommand}"/>
|
||||
<viewmodel:StudentViewModel MouseDoubleClickCommand="{Binding MouseDoubleClickCommand}"/>
|
||||
</i:Interaction.Behaviors>
|
||||
</DataGrid>
|
||||
</StackPanel>
|
||||
|
@@ -16,7 +16,7 @@ namespace DataGridEventTriggerSample.ViewModel
|
||||
{
|
||||
internal class StudentViewModel : Behavior<DataGrid>, INotifyPropertyChanged
|
||||
{
|
||||
public static readonly DependencyProperty MouseDownProperty = DependencyProperty.Register(nameof(MouseDownCommand), typeof(ICommand), typeof(StudentViewModel), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty MouseDoubleClickProperty = DependencyProperty.Register(nameof(MouseDoubleClickCommand), typeof(ICommand), typeof(StudentViewModel), new PropertyMetadata(null));
|
||||
|
||||
private ObservableCollection<Student> _students;
|
||||
|
||||
@@ -53,10 +53,10 @@ namespace DataGridEventTriggerSample.ViewModel
|
||||
}
|
||||
|
||||
|
||||
public ICommand MouseDownCommand
|
||||
public ICommand MouseDoubleClickCommand
|
||||
{
|
||||
get { return (ICommand)GetValue(MouseDownProperty); }
|
||||
set { SetValue(MouseDownProperty, value); }
|
||||
get { return (ICommand)GetValue(MouseDoubleClickProperty); }
|
||||
set { SetValue(MouseDoubleClickProperty, value); }
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
@@ -65,7 +65,7 @@ namespace DataGridEventTriggerSample.ViewModel
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public void OnDataGridMouseDown(object sender, MouseEventArgs e)
|
||||
public void OnDataGridMouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
DataGrid? dataGrid = sender as DataGrid;
|
||||
if (dataGrid == null)
|
||||
@@ -91,12 +91,12 @@ namespace DataGridEventTriggerSample.ViewModel
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
this.AssociatedObject.MouseUp += OnDataGridMouseDown;
|
||||
this.AssociatedObject.MouseDoubleClick += OnDataGridMouseDoubleClick;
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
this.AssociatedObject.MouseUp += OnDataGridMouseDown;
|
||||
this.AssociatedObject.MouseDoubleClick += OnDataGridMouseDoubleClick;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user