首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF ToolBar和StackPanel在裁剪时自动转换ClipToBounds=“真”

WPF ToolBar和StackPanel在裁剪时自动转换ClipToBounds=“真”
EN

Stack Overflow用户
提问于 2017-08-02 14:10:24
回答 2查看 522关注 0票数 2

我需要在WPF中显示它边界外的工具栏中的一些子项(当光标在工具栏上盘旋时,工具栏上的按钮会增长)。

图1:右面板行为: ClipToBounds="False“

当ClipToBounds="False“和所有按钮在工具栏中都有一个位置时,一切都是正确的。当面板的一部分被窗口的边缘裁剪,并且没有一些按钮的位置时,就会发生故障。在本例中,ToolBar和StackPanel自动将ClipToBounds属性切换到"True“,并开始裁剪子文件。

图2:错误的面板行为: ClipToBounds快照为“真”

我是否可以禁用此行为,或者除了在最上面的宽透明容器上绘制按钮之外,没有其他方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-08 08:05:40

我的解决方案(只需将工具栏划分为层):

代码语言:javascript
复制
<Window x:Class="ZoomBarMockup.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="200" Width="300">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>

        <Rectangle Grid.Row="0" Fill="#CCC"/>
        <Rectangle Grid.Row="2" Fill="#CCC"/>

        <!-- Decorative toolbar background strip -->
        <Border Grid.Row="1">
            <Border.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="#FFF" Offset="0"/>
                    <GradientStop Color="#DDD" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>            
        </Border>

        <!-- Wide transparent panel with negative margin -->
        <StackPanel Grid.Row="1" Orientation="Horizontal" ClipToBounds="False"
                    Height="50" Margin="0 -10 0 -10">
            <Ellipse Fill="Orange" Height="50" Width="50" Margin="5 0"/>
            <Ellipse Fill="Orange" Height="50" Width="50" Margin="5 0"/>
            <Ellipse Fill="Orange" Height="50" Width="50" Margin="5 0"/>
            <Ellipse Fill="Orange" Height="50" Width="50" Margin="5 0"/>
            <Ellipse Fill="Orange" Height="50" Width="50" Margin="5 0"/>
        </StackPanel>

    </Grid>
</Window>
票数 3
EN

Stack Overflow用户

发布于 2018-07-26 12:35:15

可以禁用面板的默认裁剪行为。但为了做到这一点,您必须扩展现有的面板之一,或者实现您自己的面板:

代码语言:javascript
复制
class NoClipStackPanel : StackPanel
{
    protected override Geometry GetLayoutClip(Size layoutSlotSize)
    {
        return null;
    }
}

请查看这个答案以获得有关不同裁剪方法的更多详细信息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45463270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档