[英]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
中定义,这意味着我无法直接设置ContentControl
的Panel.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.