获取附加属性继承以进行传播

编程入门 行业动态 更新时间:2024-10-28 14:24:56
本文介绍了获取附加属性继承以进行传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法将附加属性值从树中从父级传播到可视层次结构中的子级。设置如下:

I am having trouble getting an attached property value to propagate down the tree from a parent to a child in the visual hierarchy. The setup is as follows:

我有一个实例化Viewport3D的自定义面板。然后Panel处理添加和删除的子项,为每个子项创建和添加一个继承的Visual3D类。

I have a custom panel that instantiates a Viewport3D. The Panel then handles the child added and removed to create and add an inherited Visual3D class for each child item.

我试图声明一个名为AttachedToggle属性的附加属性。我希望将此属性驻留在名为AttachedToggle的外部所有者类中,该类实现单个附加依赖项属性IsChecked,并允许父Panel或任何子Visual3D元素能够更改值并具有其他元素的实例价值反映了变化。 Panel和Visual3D类都不是从公共基础继承的。可以这样做吗?

I am trying to declare an attached property called AttachedToggle property. I would like to have this property reside in an external owner class called AttachedToggle which implements the single attached dependency property IsChecked and allow either the parent Panel or any of the children Visual3D elements to be able to change the value and have the other elements' instance values reflect the change. Neither the Panel nor the Visual3D class inherit from a common base. Can this be done?

我可以使用Set / GetValue从应用程序代码成功更改IsChecked的父实例和子实例值,但无法进行传播更改。

I can successfully change both the parent and child instance value of IsChecked from application code using Set/GetValue but am unable to get the change to propagate.

推荐答案

根据属性值继承。确保您注册该属性的调用如下所示:

This should work fine, according to the docs on Property Value Inheritance. Make sure that your call to register the property looks like:

public static readonly DependencyProperty IsChecked = DependencyProperty.RegisterAttached( "IsChecked", typeof(Boolean), typeof(AttachedToggle), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits) );

- 继承标志。请参阅 FrameworkPropertyMetadata (和 FrameworkPropertyMetadataOptions - 您也可以使用 OverridesInheritanceBehavior (如果需要)。

-Note the Inherits flag. See the docs for FrameworkPropertyMetadata (and FrameworkPropertyMetadataOptions - you can use OverridesInheritanceBehavior if needed ) as well.

更多推荐

获取附加属性继承以进行传播

本文发布于:2023-10-28 00:31:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534977.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!