如何在网格中设置用户控件的z-index?

时间:2018-05-05 18:10:09

标签: c# wpf wpf-controls z-index

当我尝试将z-index设置为更高的索引时,它会给我一个错误:Member' Panel.GetZIndex(UIElement)'无法使用实例引用访问;用类型名称来限定它。即使我已经尝试过实际的类GridPanel.GetZIndex

  private void Window_Loaded(object sender, RoutedEventArgs e)
    {
       int zOrder = Panel.GetZIndex(pickupDineControl);
        Panel.SetZIndex(pickupDineControl, (int)4);

    }


<Grid x:Name="panel">
   <local:menuControl Grid.Row="1" Panel.ZIndex="1"  />
    <local:pickupDineControl Grid.Row="1" x:Name="pdcontrol" 
     Panel.ZIndex="2"  />
    <local:mainControl Grid.Row="1"  x:Name="maincontrol" Panel.ZIndex="3"/>

</Grid>

1 个答案:

答案 0 :(得分:0)

GetZIndex方法是静态的,你无法在实例上调用它。您应该使用类名。例如:

int zOrder = Panel.GetZIndex(pdcontrol);