lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.03k stars 666 forks source link

DataGrid selection and right click Event #1085

Open aliajboy opened 1 month ago

aliajboy commented 1 month ago

Describe the bug

here is my xaml in WPF UI for datagrid: <ui:DataGrid IsHitTestVisible="True" FlowDirection="RightToLeft" HeadersVisibility="Column" Name="dgvCardex" AutoGenerateColumns="False" IsReadOnly="True" MouseDoubleClick="dgvCardex_MouseDoubleClick" CanUserAddRows="False" CanUserDeleteRows="False" SelectionMode="Extended" SelectionUnit="FullRow" >

           `<ui:DataGrid.Resources>
               <Style TargetType="DataGridRow">
                   <EventSetter Event="MouseRightButtonUp" Handler="dgvCardex_MouseRightButtonUp"/>
               </Style>
           </ui:DataGrid.Resources>
           <ui:DataGrid.ContextMenu>
               <ContextMenu>
                   <MenuItem Header="گردش کالا" Click="MenuItem_Click_1"/>
                   <MenuItem Header="ویرایش محصول" Click="MenuItem_Click"/>
                   <MenuItem IsEnabled="False" Header="حذف محصول" Name="deleteProduct" Click="deleteProduct_Click"/>
               </ContextMenu>
           </ui:DataGrid.ContextMenu>
           <ui:DataGrid.Columns>
               <DataGridTextColumn Header="کد محصول" Width="80" Binding="{Binding Sku}"/>
               <DataGridTextColumn Header="نام کالا" Width="600" Binding="{Binding Name}" />
               <DataGridTextColumn Header="انبار 1" Width="50" Binding="{Binding Quantity}" />
               <DataGridTextColumn Header="انبار 2" Width="50" Binding="{Binding SecondQuantity}" />
               <DataGridTextColumn Header="موجودی کل" Width="80" Binding="{Binding TotalQuantity}" />
               <DataGridTextColumn Header="نقطه سفارش" Width="90" Binding="{Binding OrderPoint}" />
               <DataGridTextColumn Header="مکان قفسه" Width="80" Binding="{Binding ShelfPosition}" />
               <DataGridTextColumn Header="مکان کارتن" Width="90" Binding="{Binding BoxPosition}" />
               <DataGridTextColumn Header="قیمت خرید" Width="90" Binding="{Binding BuyPrice}" />
               <DataGridHyperlinkColumn Header="لینک" Width="*" Binding="{Binding Link}" >
                   <DataGridHyperlinkColumn.ElementStyle>
                       <Style TargetType="TextBlock">
                           <EventSetter Event="Hyperlink.Click" Handler="OnHyperlinkClick"/>
                       </Style>
                   </DataGridHyperlinkColumn.ElementStyle>
               </DataGridHyperlinkColumn>
           </ui:DataGrid.Columns>
       </ui:DataGrid>`

and was using exact same without WPF UI. I just wanted to get row details when I right click. but It seems that I can't do that here. I have to first click on the row I want and then right click to get the row. and another thing is that when I hit on a row, nothing shows to user like changing row background or something.

I know that WPF UI not using this code so the problem must be from these lines: <Style TargetType="DataGridRow"> <EventSetter Event="MouseRightButtonUp" Handler="dgvCardex_MouseRightButtonUp"/> </Style>

To Reproduce

just make a datagrid. you will see that no background change happen when you click and right click event wont get currentItem.

Expected behavior

To Get Row Data!

Screenshots

Screenshot 2024-05-12 002421

OS version

Windows 11 latest update VS 2022 17.9.6

.NET version

8.0.4

WPF-UI NuGet version

3.0.4

Additional context

No response