Auto Height in combination with MaxHeight

后端 未结 1 478
旧巷少年郎
旧巷少年郎 2020-12-31 03:46

I am facing a problem with setting the following xaml layout:

RowHeightAuto.xaml



        
相关标签:
1条回答
  • 2020-12-31 04:35

    This is exactly as you say it is.

    The reason why you do not see the Scrollbar's is because even though the Grid Clip's the DataGrid, it's merely a Clip, the ActualHeight of the DataGrid is the height it would get if allowed to show all it's children. You are thus not seeing it's scrollbar's. ActualHeight is so cos it's allowed to get all the space it wants with Height="Auto" on the Grid. The reason I wouldn't call this a bug personally is cos you might desire this behavior if you want to play with the ClipToBounds property of the Grid for certain animations and this is the behavior you desire. Thinking about this, I actually think I'd call this a bug too in terms of "Not desirable functionality" than "Incorrect output"

    To get the behavior your looking for,

    • Apply the MaxHeight on the DataGrid or use Grid RowDefinition.Height="*" <- both as you mentioned (Not sure why you say this is not what you want to do?)
    • Or you could also use a RelativeSourceBinding on the DataGrid

    something like -

    <DataGrid Name="DataGrid1" 
              Grid.Row="1"
              Height="{Binding RelativeSource={RelativeSource FindAncestor,
                               AncestorType={x:Type Grid}},
                               Path=RowDefinitions[1].ActualHeight}">
    

    For such issues Snoop is your friend. You can easily check this behavior and realize why the scrollbar's aren't shown when you check the ActualHeight on your DataGrid using Snoop and see it allocates quite a bit more height to the child control.

    0 讨论(0)
提交回复
热议问题