繁体   English   中英

WPF ContentControl将ZIndex设置为子ZIndex

[英]WPF ContentControl set ZIndex to child ZIndex

我需要能够基于ContentControl内的子控件设置ContentControl的Z-Index,即父控件。

这是我的小例子:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
    <Rectangle Fill="Green" Width="100" Height="100" Panel.ZIndex="5"/>
    <ContentControl>
      <Rectangle Fill="Red" Width="100" Height="100" Panel.ZIndex="10" />
    </ContentControl>
  </Grid>
</Page>

在此示例中,在Red Rectangle声明的Panel.ZIndex无效。

我想到了两个选择:

  • 让父级绑定到子级的Panel.ZIndex
  • 让孩子在其父Panel.ZIndex上设置Panel.ZIndex

我不知道如何做这两个选项之一。

最终,我的子控件在使用ContentControl进行应用的DataTemplate中定义,这意味着我无法直接设置ContentControlPanel.ZIndex属性

尝试这个:

<Grid>
    <Rectangle Fill="Green" Width="100" Height="100" Panel.ZIndex="5"/>
    <ContentControl Panel.ZIndex="{Binding Content.(Panel.ZIndex), RelativeSource={RelativeSource Self}}">
        <Rectangle Fill="Red" Width="100" Height="100" Panel.ZIndex="10" />
    </ContentControl>
</Grid>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM