我制作了一个简单的 XAML 文档查看器,它使用了许多我们自己的值转换器,当然还有内置的值转换器。存在 DependencyProperty.UnsetValue 绑定是预期行为。
我遇到一个问题,文档的结果视图在这种情况下就像内置 BooleanToVisibilityConverter 返回“隐藏”一样。我原以为它会表现得好像传入的值是 false 一样。我什至不知道“隐藏”是一个可能的结果,并且 MS 文档。
由于我不想更改文档本身以适应需要,因此我不打算制作自己的转换器,其行为符合我的预期。有什么想法可以在这里得到我想要的东西,或者甚至确认我所看到的有意义吗?
I've made a simple viewer of XAML documents that use a number of our own value converters, as well as built in ones, of course. It is expected behavior that there are DependencyProperty.UnsetValue bindings present.
I'm encountering a problem where the resulting view of my document acts like the built-in BooleanToVisibilityConverter is returning "Hidden" in that situation. I had expected it to act as if false was the value passed in. I was not even aware that "Hidden" was a possible result, and no such thing is mentioned in the MS docs.
Since I don't want to be changing the documents themselves to suit, I'm not planning to make a converter of my own that behaves as I expect. Any ideas out there to get what I want here, or even confirmation that what I'm seeing makes sense?
发布评论
评论(1)
BooleanToVisibilityConverter
返回一个Visibility
。如果您查阅文档,您会发现< code>Hidden 是一个有效值。导致DependencyProperty.UnsetValue
的绑定不会尝试通过其关联的转换器转换该值。它有效地关闭了绑定,即它应该具有与绑定根本不存在相同的结果。在这种情况下,您的
隐藏
值将来自其他地方。要了解确定依赖属性值的机制,请查看有关依赖属性优先级的文档。在您的情况下,它很可能是继承的或默认值(但这只是猜测!)The
BooleanToVisibilityConverter
returns aVisibility
. If you consult the documentation, you will find thatHidden
is a valid value. A binding that results inDependencyProperty.UnsetValue
will not attempt to convert this value via its associated converter. It effectively turns off the binding, i.e. it should have the same result as if the binding was not present at all.In this case, your
Hidden
value will be coming from elsewhere. To understand the mechanism for determining a dependency property value, look at the documentation regarding dependency property precedence. In your case, it is most likely an inherited, or default value (but that is just a guess!)