執行LeftDoubleClick我實現:如何在DataGrid中
<DataGrid Name="DataGridProcesso" AutoGenerateColumns="False" ItemsSource="{Binding CollectionView}" CanUserReorderColumns="False" CanUserSortColumns="True" AlternatingRowBackground="#D1DFE7" IsSynchronizedWithCurrentItem="True">
<DataGrid.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding ItemDoubleClickCommand}" />
</DataGrid.InputBindings>
...
但如果我點擊六次(3雙擊) 我覺得在電池內部發生的第一次點擊,細胞後,終於在DoubleClick才起作用行(我只想,我不確定),我只想當LeftDoubleClick發生在單元格觸發我的事件。
出了什麼問題?
我的DataGrid的全碼:
<DataGrid Name="DataGridProcesso" AutoGenerateColumns="False" ItemsSource="{Binding CollectionView}" CanUserReorderColumns="False" CanUserSortColumns="True" AlternatingRowBackground="#D1DFE7" IsSynchronizedWithCurrentItem="True">
<DataGrid.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ItemDoubleClickCommand}" />
</DataGrid.InputBindings>
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Padding" Value="0,10,0,10" />
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0,0,0,0"/>
</Style>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="BorderBrush" Value="#CCC"/>
<Setter Property="BorderThickness" Value="0,0,1,0"/>
<Setter Property="Cursor" Value="Hand" />
<Setter Property="FontFamily" Value="Segoe" />
<Setter Property="FontSize" Value="14" />
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Data" Width="Auto" HeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Data,Mode=OneTime}" ToolTip="Data" HorizontalAlignment="Right"></Label>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Número" Width="Auto" HeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Numero,Mode=OneTime}" ToolTip="Número"></Label>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Descrição" Width="*" HeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Descricao, Mode=OneTime}" ToolTip="Descrição"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Andamento" Width="Auto" HeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Andamento.Descricao, Mode=OneTime}" ToolTip="Andamento"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Lembrete" Width="Auto" HeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Lembrete, Mode=OneTime}" ToolTip="Lembrete"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
視圖模型的部分:
private ObservableCollection<Processo> _processos;
public ObservableCollection<Processo> Processos
{
get { return _processos; }
set
{
if (value != _processos)
{
_processos = value;
NotifyPropertyChanged(nameof(Processos));
}
}
}
private ICollectionView _collectionView;
public ICollectionView CollectionView
{
get
{
return _collectionView;
}
set
{
_collectionView = value;
NotifyPropertyChanged(nameof(CollectionView));
}
}
public ICommand ItemDoubleClickCommand => new Command<MainWindowViewModel>(a =>
{
AlterarProcesso((Processo)CollectionView.CurrentItem);
});
你能告訴我們的視圖模型 – Rohit
好吧,我編輯的代碼 –