WPF:如何制作 Expander 溢出和填充窗口

发布于 2024-09-10 04:58:29 字数 1837 浏览 2 评论 0原文

我正在尝试创建一个扩展器,它有一个切换按钮/标题作为左侧的细条,但扩展时会填充窗口的其余部分,甚至填充已经存在的材料。

我不太确定最好的方法是什么。我想到的可能是一个有两列的网格。首先是膨胀剂,其次是其他材料。接下来,我将有一个触发器,当 Expander IsExpanded 时,它将第二列宽度设置为零。

我不太确定如何让它发挥作用,甚至不确定如何正确地做到这一点。

这是一些代码示例:

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Name="SecondColumn" Width="*" />
        </Grid.ColumnDefinitions>


        <Expander ExpandDirection="Right" IsExpanded="True">

            <Expander.Resources>
                <Style TargetType="Expander">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Expander" >

                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsExpanded" Value="True" >
                                        <Setter TargetName="SecondColumn" Property="ColumnDefinition.Width" Value="0" />
                                    </Trigger>
                                </ControlTemplate.Triggers>

                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Expander.Resources>

            <ListBox >
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>
        </Expander>

        <TabControl Grid.Column="1" />

    </Grid>

我不想在展开时看到列表框,否则 TabControl

有什么想法吗?

I'm trying to create a expander that has a togglebutton/header as a slim bar to the left but when expanded fills over the rest of the window, even over material that's already there.

I'm not really sure what the best way to do it is. I thought perhaps of a grid with 2 columns. First would have the expander, second the other material. Next I would have a trigger that would set the second column width to zero when the Expander IsExpanded.

I'm not really sure how to get that to work or even how to do it properly.

Here is some code example:

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Name="SecondColumn" Width="*" />
        </Grid.ColumnDefinitions>


        <Expander ExpandDirection="Right" IsExpanded="True">

            <Expander.Resources>
                <Style TargetType="Expander">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Expander" >

                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsExpanded" Value="True" >
                                        <Setter TargetName="SecondColumn" Property="ColumnDefinition.Width" Value="0" />
                                    </Trigger>
                                </ControlTemplate.Triggers>

                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Expander.Resources>

            <ListBox >
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>
        </Expander>

        <TabControl Grid.Column="1" />

    </Grid>

I wan't the listbox to be seen when expanded, otherwise the TabControl

Any ideas?

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

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

发布评论

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

评论(1

猫弦 2024-09-17 04:58:29

听起来您想做类似的事情 Karl Shifflett 的示例在这里。在本例中,他只是修改内容控件的 z-index 并手动设置行高以产生弹出窗口的错觉,因此您需要确保您没有尝试 ZIndex其他视觉元素类似。

您需要确保在 Expander 上设置 ColumnSpanRowSpan,以便在扩展时覆盖这些行的内容。

It sounds like you're wanting to do something similar to Karl Shifflett's example here. He's just modifying the z-index of the content control in this case and setting the row height manually to give the illusion of a popup, so you'd want to make sure you're not trying to ZIndex other visual elements similarly.

You will want to make sure you're setting ColumnSpan and RowSpan on your Expander so that when it does expand it covers the content of those rows.

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