This commit is contained in:
2023-06-27 14:06:37 +09:00
parent 5a55141ab4
commit 777cc3c474
18 changed files with 471 additions and 9 deletions

View File

@@ -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>

View File

@@ -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;
}
}
}