[英]Can't set Canvas ZIndex in WPF
I have code xaml like this: 我有这样的代码xaml:
Now I change Height
of wp_2
to 450
and it's will bigger than stackMain
, I set Canvas.ZIndex="100"
in order to wp_2
can display all but it still hidden a part by stackPanel: 现在,我将
wp_2
Height
wp_2
为450
,它将大于stackMain
,我设置Canvas.ZIndex="100"
以便wp_2
可以显示所有但它仍然被stackPanel隐藏的一部分: Does anyone know to fix it?
有谁知道要修复它? Thank you all!
谢谢你们!
1.Give margin -50 top so that it begin from top(reinitialize from top). 1.给裕度-50 top使其从顶部开始(从顶部重新初始化)。
2.In wrap panel every child control start from ending position of its elder. 2.在包装面板中,每个子控件均从其上一个控件的结束位置开始。
(In this case yellow one starts from ending of red.) Give Margin="0,-50,0,0" to yellow one (在这种情况下,黄色从红色的结尾开始。)给Margin =“ 0,-50,0,0”赋予黄色
<WrapPanel Background="Yellow" Height="50" Margin="0,-50,0,0" ></WrapPanel>
For the scenario that you mentioned using Grid
is the best solution. 对于您提到的使用
Grid
的方案是最佳解决方案。 Please refer to below code: 请参考以下代码:
<Grid Background="Black">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<WrapPanel Name="Wp1" Background="Red"/>
<WrapPanel Grid.Row="1" Name="Wp2" Background="Yellow" Height="500"/>
EDITED EDITED
As you want another layer for your WrapPanel than you can wrap it inside Canvas
. 由于需要WrapPanel的另一层,而不是将其包装在
Canvas
。
<Grid x:Name="mainGrid" Background="Black">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<WrapPanel Name="Wp1" Background="Red"/>
<Canvas Grid.Row="1" Panel.ZIndex="100" Height="500" Width="{Binding ActualWidth, ElementName=mainGrid}">
<WrapPanel Name="Wp2" Background="Yellow" Height="400" Width="{Binding ActualWidth, ElementName=mainGrid}"/>
</Canvas>
</Grid>
Maybe you can do something like this? 也许您可以做这样的事情?
<Grid Background="Aquamarine" Margin="0 0 0 -270">
<Grid Background="Black" Margin="0 10 0 313">
<StackPanel Margin="0 0 0 -500">
<WrapPanel Background="Red" Height="50"/>
<WrapPanel Background="Yellow" Height="450"/>
</StackPanel>
</Grid>
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.