【问题标题】:How to place an UserControl in foreground?如何在前台放置用户控件?
【发布时间】:2014-06-13 08:34:43
【问题描述】:

我需要在屏幕上显示一个 UserControl,最重要的是。

使用以下代码 UserControl 在 ContentGrid 下显示内容。

如何将 UserControl 置于前台?


Main.xaml

<Grid x:Name="LayoutRoot">
    <local:AdvertisementsFullScreen>
    </local:AdvertisementsFullScreen>

【问题讨论】:

    标签: c# wpf silverlight


    【解决方案1】:

    ZIndex

    http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.zindex.aspx

    <Grid>
    <Grid Panel.ZIndex="1">
        <Rectangle Fill="Blue" Width="50" Height="50" Panel.ZIndex="1" />
        <Rectangle Fill="Red" Width="50" Height="50" Panel.ZIndex="0" />
    </Grid>
    <Grid Panel.ZIndex="0">
        <Rectangle Fill="Green" Width="50" Height="50" Panel.ZIndex="0" />
        <Rectangle Fill="Yellow" Width="50" Height="50" Panel.ZIndex="0" />
    </Grid>
    

    【讨论】:

      【解决方案2】:

      使用

      <UserControl Panel.ZIndex="100" />
      

      在我的 UserControl 上,解决了我的问题。

      【讨论】:

        【解决方案3】:

        有多种方法可以实现您的目标。一种方法是在其上设置Panel.ZIndex attached property

        <local:AdvertisementsFullScreen Panel.ZIndex="10" />
        

        另一个只是在 XAML 页面上的其他控件下声明它:

        <local:AdvertisementsFullScreen /> 
        <local:AdvertisementsFullScreen /> <!-- This one is on top -->
        

        第三种可能更合适的方法是使用Adorner ClassAdorner Layer 是显示 UI 元素的普通层之上的可视层。虽然它通常不用于显示整个UserControls,但它可能的。请在 Stack Overflow 上查看WPF adorner with controls inside 问题的答案,了解更多信息。

        【讨论】:

        • 啊……我花了太长时间了,嗯?嗯。
        猜你喜欢
        • 1970-01-01
        • 2013-03-24
        • 2012-06-13
        • 1970-01-01
        • 2021-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多