开发者

Why does BooleanToVisibilityConverter seem to return "Hidden" (not "Collapsed") when passed DependencyProperty.UnsetValue?

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开发者_JS百科 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?


The BooleanToVisibilityConverter returns a Visibility. If you consult the documentation, you will find that Hidden is a valid value. A binding that results in DependencyProperty.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!)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜