Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable column reordering in WPF with Style

I have an application with a lot of ListView controls using the GridView layout. All of these use a custom Style customStyle. I want to disable column reordering in all of these ListView controls.

Can I do this without touching all of the controls using the existing Style? I tried this, but it doesn't seem to work:

<Style x:Key="customStyle"
       BasedOn="{StaticResource ResourceKey={x:Type ListView}}"
       TargetType="{x:Type ListView}">
    <Setter Property="GridView.AllowsColumnReorder" Value="False" />
    ...
</Style>

Thanks!

Update: If this is not possible, is there a way to disable the column reordering by default in my application?

Update: I also tried this, which doesn't work. Probably because GridView doesn't have a Style property.

<Style TargetType="{x:Type GridView}">
    <Setter Property="AllowsColumnReorder" Value="False" />
    ...
</Style>
like image 254
aKzenT Avatar asked Dec 11 '25 09:12

aKzenT


2 Answers

Here's what you should have done:

In this style definition

<Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="ScrollViewer">

There is a

<GridViewHeaderRowPresenter

And it has an attribute AllowsColumnReorder hard code it to false.

...

I know ... Two year old thread. But I bet people still read it.

like image 181
ciuppinho Avatar answered Dec 13 '25 11:12

ciuppinho


Just simply add this attributes to your datagrid tag

CanUserResizeColumns="False"
like image 40
Call Me Juan Avatar answered Dec 13 '25 12:12

Call Me Juan