为什么 BooleanToVisibilityConverter 似乎返回“Hidden” (不是“折叠”)当传递 DependencyProperty.UnsetValue 时?

发布于 2024-11-15 06:16:28 字数 469 浏览 2 评论 0 原文

我制作了一个简单的 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×纯※雪 2024-11-22 06:16:28

BooleanToVisibilityConverter 返回一个Visibility。如果您查阅文档,您会发现< code>Hidden 是一个有效值。导致 DependencyProperty.UnsetValue 的绑定不会尝试通过其关联的转换器转换该值。它有效地关闭了绑定,即它应该具有与绑定根本不存在相同的结果。

在这种情况下,您的隐藏值将来自其他地方。要了解确定依赖属性值的机制,请查看有关依赖属性优先级的文档。在您的情况下,它很可能是继承的或默认值(但这只是猜测!)

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!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文