0
我需要能够根据ContentControl
内的子控件设置父项ContentControl
的Z索引。WPF ContentControl将ZIndex设置为子ZIndex
这里是我的小例子:
<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>
在这个例子中,Panel.ZIndex在Red
Rectangle
宣称没有任何效果。
我想到了两个选项:
- 有家长结合孩子的
Panel.ZIndex
值 - 让孩子设置其父
Panel.ZIndex
我想不出了解如何做这两种选择。
最终我的孩子控制在一个被使用ContentControl
施加DataTemplate
定义,这意味着我不能直接设置的ContentControl
我搞砸了和需要将其用于“ContentPresenter”而不是“ContentControl”。您尽管回答了我的原始问题:)(如果您知道ContentPresenter的简单方法,可随时添加评论) – ManIkWeet
ContentPresenter是另一回事。它没有内容属性。但如果您有其他问题,请提出一个新问题。 – mm8