开发者

Why does a WPF DataGrid sometimes remain horizontally shrunk?

I have a user who sometimes sees a DataGrid that doesn't expand to fit its space: visually squeezed data grid http://www.varigence.com/images/compressedDataGrid.jpg.

I'm looking to solve the mystery of why this is happening. Usually, when the Grid first loads, the DataGrid will appear shrunk for a moment, but then expands to fill the appropriate space. The sole lead I have is that the user who sees this says it doesn't repro when he disables Aero in Windows.

I've added a (simplified) snippet of the XAML I'm using below.

Does anyone out there have ideas as to the cause?

Thanks,

-Craig

<Grid
    AllowDrop="True"
    Background="White"
    MinHeight="400"
    MinWidth="1100"
    MaxHeight="{Binding RelativeSource={RelativeSource AncestorType={x:Type Editors:DesignerEditor}}, Path=MainWindowScrollViewer.ViewportHeight, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
    MaxWidth="{Binding RelativeSource={RelativeSource AncestorType={x:Type Editors:DesignerEditor}}, Path=MainWindowScrollViewer.ViewportWidth, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"   
    >
    <Grid.ColumnDefinitions>
        <ColumnDefinition MinWidth="350" Width="*"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition MinWidth="250" Width="*"/>
    </Grid.ColumnDefinitions>
    <Border
        Grid.Column="0"
        BorderThickness="1"
        BorderBrush="{StaticResource headerBackgroundBrush}"
        CornerRadius="4"
        HorizontalAlignment="Stretch"
        Margin="10,10,0,10"
        VerticalAlignment="Stretch"
        >
        <Grid
            KeyboardNavigation.TabNavigation="Local"
            >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <TextBlock
                Grid.Row="0"
                Text="Columns"
                />
            <DataGrid:SelectingDataGrid 
                x:Name="columnDataGrid"
                Grid.Row="1"
                AutoGenerateColumns="False"
                BorderBrush="{StaticResource excelBorderBrush}"
                HorizontalAlignment="Left"
                ItemsSource="{Binding ElementName=tableEditor, Path=SelectedContext.Columns.FilterCollection}"
                RowDetailsTemplateSelector="{StaticResource columnDetailsTemplateSelector}"
                RowDetailsVisibilityMode="VisibleWhenSelected"
                SelectionMode="Extended"
                SelectionUnit="FullRow"
                >
                <DataGrid:SelectingDataGrid.ItemContainerStyle>
                    <Style
                        TargetType="{x:Type DataGridRow}"
                        BasedOn="{StaticResource {x:Type DataGridRow}}"
                        >
                        <Setter
                            Property="IsSelected"
                            Value="{Binding IsSelected, Mode=TwoWay}"
                            />
                    </Style>
                </DataGrid:SelectingDataGrid.ItemContainerStyle>
                <DataGrid:SelectingDataGrid.Columns>
                    ...
                </DataGrid:SelectingDataGrid.Columns>
            </DataGrid:SelectingDataGrid>
        </Grid>
    </Border>
    <GridSplitter 
        Grid.Column="1"     
        Background="White"
        IsTabStop="False"
        ResizeBehavior="PreviousAndNext"
 开发者_JS百科       Width="20" 
        />


I'm going to assume that you want the DataGrid to fill up the left column. If you change

HorizontalAlignment="Left"

to

HorizontalAlignment="Stretch"

it should solve the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜