XAML是否在调用IList.Add()之后设置依赖项属性值? [英] Does XAML set dependency property values AFTER calling IList.Add( )?

查看:41
本文介绍了XAML是否在调用IList.Add()之后设置依赖项属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在.NET Reflector中找到答案,但是无法对所有XamlObjectWriter意大利面条进行排序.

I tried to find the answer to this in .NET Reflector but couldn't sort through all the XamlObjectWriter spaghetti.

基本上,我有一个继承自FrameworkElement的自定义类,该类实现了IList,但需要通过某些依赖项属性值来过滤项目,以确保不会添加重复的子代.  但是所有东西都是默认的XAML阅读器(通过InitializeComponent() )提供给IList.Add()并没有将单个依赖项属性设置为XAML中的属性.  直到IList.Add()返回之后,才设置属性,到那时,我剩下的是充满垃圾的集合.

Basically I have a custom class derived from FrameworkElement that implements IList but needs to filter items by certain dependency property values to make sure duplicate children don't get added.  But everything the default XAML reader (via InitializeComponent() ) is feeding to IList.Add( ) doesn't have a single dependency property set to what was in the XAML.  The properties aren't set until after IList.Add( ) returns and by that point I'm left with a collection full of garbage.

如果对主题标题问题的回答为是",则返回否".那就像把轮胎装在汽车上,甚至不看轮胎尺寸是否合适.

If the answer to the subject header question is "Yes" then that's like putting tires on a car without even seeing if they're the right size.

我们正在使用它,是否有一种方法可以使依赖项属性本身拒绝带有异常的错误值分配,还是我们也被这种垃圾所困扰? ValidateValueCallback几乎没有用,因为它不提供所有者对象引用.

While we're at it, is there a way for dependency properties themselves to reject bad value assignments with an exception, or are we stuck with that garbage too? ValidateValueCallback is all but useless because it doesn't provide the owner object reference.

推荐答案

我对XAML调用IList.Add的方式感到困惑.为你.您能否提供更多详细信息?另外,如果您描述要尝试完成的工作的总体情况可能会有所帮助,特别是如果您不熟悉WPF,因为通常情况下 在WPF和WinForms中完成工作的方法更加简单和明显不同.
I'm confused at to how XAML is calling IList.Add for you. Can you give some more details? Also, it maybe helpful if you give a description of the bigger picture of what you are trying to accomplish especially if you are new to WPF as there are generally much easier and significantly different ways of getting things done in WPF vs WinForms.


这篇关于XAML是否在调用IList.Add()之后设置依赖项属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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