【发布时间】:2011-10-15 20:31:05
【问题描述】:
通过以下代码,我可以演示一个不透明度为 50% 的黑色面板如何位于每个矩形的顶部:
<Grid>
<Rectangle Fill="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.5" Canvas.ZIndex="1"/>
<Rectangle Fill="Red" Width="200" Height="200" Canvas.ZIndex="0"/>
<Grid>
<Rectangle Fill="Blue" Width="100" Height="100" Canvas.ZIndex="0"/>
<Rectangle Fill="Yellow" Width="50" Height="50" Canvas.ZIndex="1"/>
</Grid>
</Grid>
看起来像这样:
我希望黑色面板上方的黄色矩形,但这似乎是不可能的。
我可以通过将包含蓝色和黄色矩形的网格的 ZIndex 设置为“1”来实现接近的效果。但这也会将蓝色矩形提升到黑色之上,这是一个问题。
<Grid>
<Rectangle Fill="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.5" Canvas.ZIndex="1"/>
<Rectangle Fill="Red" Width="200" Height="200" Canvas.ZIndex="0"/>
<Grid Canvas.ZIndex="1">
<Rectangle Fill="Blue" Width="100" Height="100" Canvas.ZIndex="0"/>
<Rectangle Fill="Yellow" Width="50" Height="50" Canvas.ZIndex="1"/>
</Grid>
</Grid>
如何只获得黑色上方的黄色矩形? 在我的真实应用程序中,我有用户控件而不是矩形。我喜欢通过将其他所有内容都覆盖在半黑色阴影中来突出特定控件。
非常感谢,
【问题讨论】:
标签: c# .net wpf silverlight z-index