Pergunta

if I set a datagrid with 3 fixed width columns everything works as expected (the 3 columns measure 100):

<Window x:Class="DataGridTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<DataGrid HorizontalScrollBarVisibility="Visible" >
    <DataGrid.Columns>
        <DataGridTextColumn Width="100" Header="A" />
        <DataGridTextColumn Width="100" Header="B" />
        <DataGridTextColumn Width="100" Header="C" />
    </DataGrid.Columns>
</DataGrid>
</Window>

If I change one column to Width * when you resize the window making it smaller all of them change their width.

<Window x:Class="DataGridTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<DataGrid HorizontalScrollBarVisibility="Visible" >
    <DataGrid.Columns>
        <DataGridTextColumn Width="*" Header="A" />
        <DataGridTextColumn Width="100" Header="B" />
        <DataGridTextColumn Width="100" Header="C" />
    </DataGrid.Columns>
</DataGrid>
</Window>

Is this the expected behavior or is it a bug in WPF?

Foi útil?

Solução

this is how the datagrid works by default: the width you set on the columns is only the original width. And then when you size the datagrid down, it resizes ALL columns, independently of their original widths.

if you want your columns to keep their widths no matter what (and show a scrollbar instead, for instance), you should use MinWidth instead/as well

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top