Home > Blockchain >  WPF DataGridTextColumn adding PreviewMouseDown Event
WPF DataGridTextColumn adding PreviewMouseDown Event

Time:06-19

I want to using a keyboard in my WPF Desktop Project.Normally I'm using a datagrid and all values come from my database.My aim is when I click a cell of datagrid then must be open my custom keyboard.For this reason I want to use previewmousedown event in my datagridtextcolumn.How can I achieve that?Is anyone help me?

XAML:

<DataGrid x:Name="datagridusers" 
                                
          materialDesign:ColorZoneAssist.Background="Wheat"  
          VerticalAlignment="Top" Height="400" Margin="20 80 20 20" 
          HorizontalContentAlignment="Stretch"  
          VerticalContentAlignment="Stretch"  
          Style="{StaticResource MaterialDesignDataGrid}" 
          FontSize="15" 
          materialDesign:ScrollViewerAssist.SupportHorizontalScroll="True" 
          CanUserAddRows="False" 
          AutoGenerateColumns="False">
    <DataGrid.Columns>
        <materialDesign:DataGridTextColumn Header="USER ID" 
                                           Binding="{Binding Id}"    
                                           IsReadOnly="True">
            <DataGridTextColumn.ElementStyle>
                <Style>
                    <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                    <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </materialDesign:DataGridTextColumn>
    </DataGrid.Columns >
</DataGrid>

CodePudding user response:

As for your question

how can I use in a DatagridTextColumn this events like previewmousedown or so?

This is a copied and pasted example from a real-world project: View xaml:

    <DataGrid Grid.Row="2"
              x:Name="dataGrid"
              ItemsSource="{Binding CollectionView}"
              PreviewMouseDown="DataGrid_PreviewMouseDown">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding ItemName}"
                                Header="{Binding Source={x:Static local:AppLocalization.NameGiven}}" 
                                Width="110*" MinWidth="110"/>
        </DataGrid.Columns>
    </DataGrid>

code-behind.cs:

        private void DataGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            //  open your custom keyboard here
        }
  • Related