不填充高度的 WPF 固定选项

发布于 2024-12-03 17:28:51 字数 556 浏览 0 评论 0原文

我正在寻找一个 WPF 选项,可以在侧面显示面板,并允许您固定/取消固定它们。基本上,这意味着一个窗口,其中一个主控件位于中心,并且该主控件的左侧和右侧都有多个不同的面板。默认情况下,这些面板是折叠的,只有标题可见,如果我将鼠标悬停在它们上方,它们会在主控件上展开(不会取代主控件),但我也可以选择固定此面板,使其永久展开出,这一次迫使主中心控件调整大小。

现在,这听起来很像大多数对接控制选项,实际上我已经研究过 AvalonMixModes Synergy ,但这些选项的问题是它们的面板填满了整个高度。我希望当我将鼠标悬停在特定高度的面板上时,它会出现,我不希望它填充到屏幕上,而且我真的找不到其他任何可以做到这一点的东西。还有其他人见过这样的事情吗?

基本上,到目前为止,我自己关于如何做到这一点的想法涉及以编程方式将面板从一个固定控件移动到另一个非固定控件,但这听起来很丑陋,我喜欢替代方案。

I'm looking for a WPF option that shows panels on the sides, and allows you to pin/unpin them. Basically this means a Window, with a main control in the center and multiple different panels on both the left and right sides of this main control. These panels are collapsed by default, with just their headers visible, and if i hover over them they expand out OVER the main control (without displacing the main control), but i also have the option to pin this panel, where it stays permanantly expanded out, this time forcing the main center control to resize.

Now this sounds pretty much like most docking control options, and indeed i've looked at Avalon and MixModes Synergy , but the problem with these options is that their panels fill out the entire height. I want a panel of a specific height to come out when i hover over it, i don't want it to fill out to screen, and i can't really find anything else that does that. Anyone else seen something like this?

Basically my own ideas on how to do this so far involve programmatically moving the panel from one pinned control to another non-pinned control, but this sounds crazy ugly and i'd love alternatives.

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

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

发布评论

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

评论(1

云裳 2024-12-10 17:28:51

下面是一个纯 XAMl 示例,说明如何实现固定/取消固定功能。

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


    <DockPanel Grid.Column="1">
        <Label Content="Main Content Area" FontSize="22"
               VerticalAlignment="Center" HorizontalAlignment="Center"/>
    </DockPanel>

    <StackPanel HorizontalAlignment="Left">
        <StackPanel.Style>
            <Style>
                <Setter Property="Grid.Column" Value="1"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=LeftPinBtn,Path=IsChecked}" Value="True">
                        <Setter Property="Grid.Column" Value="0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </StackPanel.Style>
        <ToggleButton Content="Pin/Unpin" x:Name="LeftPinBtn"/>
    </StackPanel>

</Grid>

在上面的代码中,

  • 左侧面板位于(浮动)主要内容的同一网格列上。
  • 当选中 ToggleButton 时,它们会跳转到各自的位置
    对接网格列。

您可以自定义此示例和包括将显示/隐藏面板的鼠标悬停事件。

  • 在右侧添加网格列 + Horizo​​ntalAlignment="Right"
    会给你正确的面板。
  • 类似地使用(而不是列)和垂直对齐
    将添加顶部/底部引脚功能。

Here is a pure XAMl example of how you can achieve Pin/Unpin functionality.

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


    <DockPanel Grid.Column="1">
        <Label Content="Main Content Area" FontSize="22"
               VerticalAlignment="Center" HorizontalAlignment="Center"/>
    </DockPanel>

    <StackPanel HorizontalAlignment="Left">
        <StackPanel.Style>
            <Style>
                <Setter Property="Grid.Column" Value="1"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=LeftPinBtn,Path=IsChecked}" Value="True">
                        <Setter Property="Grid.Column" Value="0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </StackPanel.Style>
        <ToggleButton Content="Pin/Unpin" x:Name="LeftPinBtn"/>
    </StackPanel>

</Grid>

In the above code,

  • The left panel lies (floats) on the same grid column of the Main content.
  • When the ToggleButton is checked they jump to their respective
    docking grid column.

You may customize this example & include the mouseover events which will show/hide the panels.

  • Adding a Grid column to the right + HorizontalAlignment="Right"
    will give you right panel.
  • Similarly using Rows (instead of columns) & VerticalAlignment
    will add top/bottom pin functionality.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文