Combine expander and grid (resizable expander)

喜欢而已 提交于 2019-11-27 09:25:34

Not sure what you are trying to accomplish but i think conceptually the Grid should be part of the Expander.Content, would this work for you?

<Expander Header="Test" ExpandDirection="Right" HorizontalAlignment="Left" Background="LightBlue">
    <Expander.Content>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="5"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="Lorem ipsum dolor sit"/>
            <GridSplitter Grid.Column="1" Width="5" ResizeBehavior="PreviousAndCurrent" ResizeDirection="Columns"/>
        </Grid>
    </Expander.Content>
</Expander>

Edit: Removed all the triggering from the first column as it seemed unnecessary.

Also: For this to work vertically the GridSplitter's HorizontalAlignment must be set to Stretch, otherwise it will have zero width by default (of course everything else that is orientation-specific must be adapted as well but that is straightforward)

HorizontalAlignment is the Microsoft .NET property accessor for what is in reality a dependency property. This particular dependency property quite frequently has its apparent "default" value set differently in subclassed elements, particularly controls. [...] For example, the apparent "default" of HorizontalAlignment for a Label control will be Left, even though Label inherits HorizontalAlignment direct from FrameworkElement. This is because that value was reset within the default style of Label, within the style's control template.

Sonorx

Maybe this will help to solve your "column collapse" problem

XAML:

Add in <Grid> Name="expGrid" and add in <Expander> Collapsed="Expander_Collapsed"

C# Code:

private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
  var colomnIndex = Grid.GetColumn(sender as Expander);
  var colomn = expGrid.ColumnDefinitions[colomnIndex];
  colomn.Width = GridLength.Auto;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!