0

In my current implementation, I spawn tabs and grids dynamically.

Basically, a new grid needs to be created by a double click on a any row of a previous grid and use the row data for other provessing.

this.AddHandler(DataGrid.MouseDoubleClickEvent, new RoutedEventHandler    (Generic_DoubleClick));    

This handles for any double click even outside the grid and not specifically for the grid.

I need to find a handler which can return the row values specifically to that grid. Please suggest a workaround or a easier way of doing this.

Thanks.

1 Answer 1

1

Handle the double click routed event from datagrid row of the datagrid.

   <tk:DataGrid>
        <tk:DataGrid.Resources>
            <Style TargetType="{x:Type tk:DataGridRow}">
                <EventSetter Event="MouseDoubleClick"
                             Handler="DataGridRow_MouseDoubleClick"/>
            </Style>
        </tk:DataGrid.Resources>
        <tk:DataGrid.ItemsSource>
            <x:Array Type="{x:Type TextBlock}">
                <TextBlock Text="1" Tag="1.1"/>
                <TextBlock Text="2" Tag="1.2"/>
                <TextBlock Text="3" Tag="1.3"/>
                <TextBlock Text="4" Tag="1.4"/>
            </x:Array>
        </tk:DataGrid.ItemsSource>
        <tk:DataGrid.Columns>
            <tk:DataGridTextColumn Header="Text" Binding="{Binding Text}"/>
            <tk:DataGridTextColumn Header="Tag" Binding="{Binding Tag}"/>
        </tk:DataGrid.Columns>
    </tk:DataGrid>

In code behind

    private void DataGridRow_MouseDoubleClick(
           object sender, MouseButtonEventArgs e)
    {
        var dgRow = sender as Microsoft.Windows.Controls.DataGridRow;
        var cellContentElement = e.OriginalSource as UIElement;
    }

Bonus is cellContentElement is the content element of the cell that was double clicked on the row ... e.g. in case of DataGridTextColumn it will be TextBlock in the cell.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.