组合扩展器和网格(可调整大小的扩展器)

发布于 10-30 23:49 字数 605 浏览 6 评论 0原文

我想要一个类似可调整大小的扩展器之类的东西。我的基本想法是这样的:

<Grid HorizontalAlignment="Left">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="2" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <Expander Grid.Column="0" ExpandDirection="Right">
          ...
    </Expander>

    <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

    ...
</Grid>

问题是:如果我移动网格分离器并折叠扩展器,我会得到一个很大的空白区域。怎样才能让整根柱子倒塌呢?或者有另一种方法可以使扩展器“调整大小”

I would like to have something like a resizable Expander. My basic idea was something like this:

<Grid HorizontalAlignment="Left">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="2" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <Expander Grid.Column="0" ExpandDirection="Right">
          ...
    </Expander>

    <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

    ...
</Grid>

The problem with this: if i move the grid splitter and collaps the expander i got a big empty area. How can make the entire column collapse? Or is there another way to make the expander "resizable"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

執念2024-11-06 23:49:55

不确定您想要完成什么,但我认为从概念上讲,Grid 应该是 Expander.Content 的一部分,这对您有用吗?

<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>

编辑:从第一列中删除了所有触发,因为它似乎没有必要。

另外:为了使其垂直工作,GridSplitter 的 Horizo​​ntalAlignment 必须设置为 Stretch,否则默认宽度为零(当然,特定于方向的其他所有内容也必须进行调整,但这很简单)

Horizo​​ntalAlignment 是 Microsoft .NET 属性访问器,用于实际的依赖属性。这种特定的依赖属性经常在子类元素(尤其是控件)中具有不同的明显“默认”值设置。 [...] 例如,Label 控件的 Horizo​​ntalAlignment 的明显“默认值”将为 Left,即使 Label 直接从 FrameworkElement 继承 Horizo​​ntalAlignment。这是因为该值已在样式的控件模板内的默认标签样式内重置。

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.

仅一夜美梦2024-11-06 23:49:55

也许这将有助于解决您的“列折叠”问题

XAML:

添加 Name="expGrid" 并添加 < /code> Collapsed="Expander_Collapsed"

C# 代码:

private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
  var colomnIndex = Grid.GetColumn(sender as Expander);
  var colomn = expGrid.ColumnDefinitions[colomnIndex];
  colomn.Width = GridLength.Auto;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文