如何屏蔽 WPF Wrappanel 的内容?

发布于 2024-12-23 11:16:26 字数 1124 浏览 1 评论 0原文

您好,感谢您的浏览!

背景

这是这个问题的扩展:

如何在 WPF 包装面板内向上或向下滑动子项?

其中我询问如何以编程方式在按钮上向上或向下滚动 WrapPanel 的内容 点击。这个问题得到了很好的回答,并且接受的解决方案效果很好。

问题

现在,我在 WrapPanel 中的缩略图在单击按钮时上下滚动,如何屏蔽 WrapPanel 以便图块在超出范围时不会显示框架?例如,我在 WrapPanel 上方有一个 StackPanel,它包含向上和向下滚动按钮,但是当我向下滚动时,缩略图会覆盖 StackPanel code> 在它们(和按钮)上方。这是到目前为止我的 XAML,请注意,缩略图在运行时添加到 WrapPanel 中:

使用 Dave Clemmer 的 XAML进行更新

,我的布局更加稳定,但最终我仍然得到 < code>WrapPanel 使其上方的 StackPanel 黯然失色。请查看滚动事件之前和之后拍摄的屏幕截图:

BEFORE SCROLL-

Before Scroll

AFTER SCROLL- 在此处输入图像描述

更新 2

根据下面 Dave 的评论将画布设置为红色背景。

在滚动之前 -

在此处输入图像描述

滚动后 -

在此处输入图像描述

Hi and thanks for looking!

Background

This is an extension on this question:

How do I slide child items up or down inside a WPF wrappanel?

In which I asked how I could programattically scroll the contents of a WrapPanel up or down on a button click. This question was kindly answered and the accepted solution works well.

Problem

Now that my thumbnails in the WrapPanel scroll up and down on a button click, how do I mask the WrapPanel so that the tiles don't show when they are outside of frame? For example, I have a StackPanel above the WrapPanel that holds the scroll up and down buttons, but when I scroll down, the thumbnails cover up the StackPanel above them (and the buttons). Here is my XAML so far, please note that the thumbnails are added to the WrapPanel at runtime:

Update

Using Dave Clemmer's XAML, my layout is steadier, but then I still end up with the contents of the WrapPanel eclipsing the StackPanel above it. Please see these screen grabs taken before and after the scroll event:

BEFORE SCROLL-

Before Scroll

AFTER SCROLL-
enter image description here

Update 2

Set canvas to red background per Dave's comment below.

BEFORE SCROLL-

enter image description here

AFTER SCROLL-

enter image description here

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

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

发布评论

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

评论(2

扎心 2024-12-30 11:16:26

好吧,我不会称之为直观的,但最终,这起作用了:

 <Border Grid.Row="1" Background="Transparent" ClipToBounds="True">       
            <Canvas>
                <WrapPanel x:Name="spContainer"  
                   Width="{Binding ActualWidth,  
                           RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">
                </WrapPanel>
            </Canvas>
 </Border>

添加边框就达到了目的。感谢戴夫的所有帮助!

Well, I wouldn't call this intuitive, but in the end, this worked:

 <Border Grid.Row="1" Background="Transparent" ClipToBounds="True">       
            <Canvas>
                <WrapPanel x:Name="spContainer"  
                   Width="{Binding ActualWidth,  
                           RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">
                </WrapPanel>
            </Canvas>
 </Border>

Adding the border did the trick. Thanks to Dave for all of your help!

陌伤ぢ 2024-12-30 11:16:26

听起来您不想要滚动条(没有 ScrollViewer)并且希望修复 StackPanel。将 StackPanelWrapPanel 保留在单独的 Grid 行中,例如:

<Grid> 
    <Grid.RowDefinitions> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <StackPanel Grid.Row="0" Height="150" HorizontalAlignment="Left" Margin="30,10,10,10" Name="stackPanel1" VerticalAlignment="Top" Width="Auto" Orientation="Horizontal" >  
        <Label Content="Home Navigator v0.1" FontFamily="Tahoma" FontSize="30" FontWeight="Bold" Foreground="White" />  
        <Button Content="Close" Height="50" Click="Button_Click" VerticalAlignment="Top"></Button>  
        <Button Content="Scroll Down" Height="50" Click="ScrollDown" VerticalAlignment="Top"></Button>  
    </StackPanel>  
    <Canvas Grid.Row="1">  
        <WrapPanel x:Name="spContainer"  
                   Width="{Binding ActualWidth,  
                           RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">  
        </WrapPanel>      
    </Canvas>  
</Grid>

It sounds like you do not want scrollbars (no ScrollViewer) and want the StackPanel to be fixed. Keep the StackPanel and WrapPanel in separate Grid rows such as:

<Grid> 
    <Grid.RowDefinitions> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <StackPanel Grid.Row="0" Height="150" HorizontalAlignment="Left" Margin="30,10,10,10" Name="stackPanel1" VerticalAlignment="Top" Width="Auto" Orientation="Horizontal" >  
        <Label Content="Home Navigator v0.1" FontFamily="Tahoma" FontSize="30" FontWeight="Bold" Foreground="White" />  
        <Button Content="Close" Height="50" Click="Button_Click" VerticalAlignment="Top"></Button>  
        <Button Content="Scroll Down" Height="50" Click="ScrollDown" VerticalAlignment="Top"></Button>  
    </StackPanel>  
    <Canvas Grid.Row="1">  
        <WrapPanel x:Name="spContainer"  
                   Width="{Binding ActualWidth,  
                           RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">  
        </WrapPanel>      
    </Canvas>  
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文