Reputation: 204746
I have a WPF DataGrid. With a single click I can edit every cell in the DataGrid.
I also want to open a new Window on a double click.
That double click event works for a normal DataGridTextColumn like this
<DataGridTextColumn Binding="{Binding Path=Name}" >
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<EventSetter Event="MouseDoubleClick" Handler="CellEditDoubleClick"/>
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
But how to do it using a Template like this when I am in editing mode of the TextBox:
<DataGridTemplateColumn Header="Weight">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Weight}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox x:Name="WeightEditTextBox" Text="{Binding Path=Weight}" >
<i:Interaction.Behaviors>
<helper:TextBoxInputRegExBehaviour RegularExpression="^\d+\,?\d*$" />
</i:Interaction.Behaviors>
</TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
Currently when in edit mode the double click does get fired.
Perfect would be a solution that works for the complete DataGrid which I do not have to add to every single column in the DataGrid.
Upvotes: 1
Views: 1299
Reputation: 8591
I think adding the "MouseDoubleClick" event handler for TextBox would work. Even it's in template.
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox x:Name="WeightEditTextBox" Text="{Binding Path=Weight}" MouseDoubleClick="WeightEditTextBox_MouseDoubleClick">
<i:Interaction.Behaviors>
</i:Interaction.Behaviors>
</TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
Upvotes: 2