WPF Canvas上没有Canvas.ZIndex或SetZIndex()属性 [英] No Canvas.ZIndex or SetZIndex() property on WPF Canvas

查看:655
本文介绍了WPF Canvas上没有Canvas.ZIndex或SetZIndex()属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改WPF画布上组件的Z顺序,但是在后面的代码中它似乎不作为XAML属性或方法存在。

I'm trying to change the Z order of components on my WPF canvas, but it doesn't seem to exist as a XAML property or method in the code behind.

这是我的XAML:

<UserControl x:Class="FrontendUI.Controls.RadialTracker"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:FrontendUI.Controls"
         mc:Ignorable="d" 
         d:DesignHeight="500" d:DesignWidth="500">
<Grid >
    <Canvas x:Name="TrackerCanvas">
    </Canvas>
</Grid>

起初我试图以编程方式执行此操作:

At first I was trying to do this programmatically:

然后我尝试添加使用XAML并设置Canvas.ZIndex的路径,该路径也不存在。虽然有Panel.ZIndex,但是我假设这是指UI中更高的内容(网格,还是用户控件本身?)

Then I tried adding a Path using XAML and setting the Canvas.ZIndex, which also didn't exist. There was the Panel.ZIndex though, but I'm assuming this is referring to something higher in the UI (the grid, or User control itself?)

不确定如何继续。有人知道为什么会这样吗?

Not sure how to proceed. Does anyone know why this is happening?

推荐答案

Canvas从Panel继承。 Panel.SetZIndex()是静态方法,而Panel.ZIndex是附加属性,这就是为什么您在xaml中看不到它的原因。

Canvas inherits from Panel. Panel.SetZIndex() is a static method and Panel.ZIndex is an attached property that is why you are not seeing it in the xaml.

为xaml中的子组件设置ZIndex。

<Canvas >
        <Button Content="Button" Panel.ZIndex="1" />
</Canvas>

要在后面的代码中为子组件设置Zindex。

Canvas.SetZIndex(control, index);




您说的 .ZIndex,但是我假设这是将
引用到UI中更高的位置(网格,还是用户控件本身?)

You said "There was the Panel.ZIndex though, but I'm assuming this is referring to something higher in the UI (the grid, or User control itself?)"

您的假设是错误的。为了满足您的要求,您需要设置Panel.ZIndex

Your Assumption is wrong. To achieve your requirement you need to set the Panel.ZIndex


您询问的:但是它们都使用Canvas。 ZIndex,有人知道为什么会这样吗?

You asked : But they all use Canvas.ZIndex, Does anyone know why this is happening?

因为ZIndex是附加属性(而不是常规依赖项属性)。

Because ZIndex is an attached property (and not a regular dependency property).

这篇关于WPF Canvas上没有Canvas.ZIndex或SetZIndex()属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆