How to set ContextMenu for GridView without breaking Fluent Theme? #11133
Answered
by
DisillusionedDeveloper
masterLazy
asked this question in
Q&A
-
|
I'm using .NET-10.0.100-rc.1.25451.107. I tried following code to create a GridView with a ContextMenu for each row: <ListView ItemsSource="{Binding Source={StaticResource EmployeeInfoDataSource}}">
<!--Menu-->
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Remove"/>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<!--List-->
<ListView.View>
<GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Employee Information">
<GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}" Header="First Name" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=LastName}" Header="Last Name" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=EmployeeNumber}" Header="Employee No." Width="150"/>
</GridView>
</ListView.View>
</ListView>But after adding I also trid to set How can I have the GridView work as expected? |
Beta Was this translation helpful? Give feedback.
Answered by
DisillusionedDeveloper
Feb 15, 2026
Replies: 1 comment 2 replies
-
|
Are there any ideas? The problem is still remained in the latest .NET 10 release. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Hi masterLazy, does using this line
<Style TargetType="ListViewItem" BasedOn="{StaticResource {x:Static GridView.GridViewItemContainerStyleKey}}">solve the second problem of your Employee-Items being rendered by their ToString-Method rather than by the Columns you defined in XAML?
When taking a look at the very bottom of ListViewItem.xaml it seems that
DefaultListViewItemStyleis set as the default style for ListViewItem. ThisDefaultListViewItemStyle(found in the same file) defines a ControlTemplate based on ListBoxItem and not on ListViewItem (is that a mistake maybe?). May humble guess is that this causes the fallback to the false rendering when overwriting ItemContainerStyle without…