IsEnabled False 如果 Binding.Source 不可用
有一个按钮,如果绑定值为 false 或 null,我希望禁用该按钮。这是我尝试过的。
<Button Content="Open" IsEnabled="{Binding SearchItem.WFBatchFolderStatus.UserCanOpen, Mode=OneWay, TargetNullValue=false, Converter={StaticResource booleanPassThru}}" />
我有一个案例,SearchItem.WFBatchFolderStatus 可以为空(并且出于有效的业务原因)。如果 SearchItem.WFBatchFolderStatus 为 null,那么我希望禁用该按钮。当 SearchItem.WFBatchFolderStatus 为 null 时,转换器不会触发。如果 SearchItem.WFBatchFolderStatus 不为 null,则转换器将触发。如果值为 null,则转换器仅返回 false,否则返回该值。但转换器永远不会看到空值。当 SearchItem.WFBatchFolderStatus 为 null 时,按钮已启用(不是我想要的)。如果我删除 TargetValue 和/或 Converter,则当 SearchItem.WFBatchFolderStatus 为 null 时按钮仍处于启用状态。
Have a button that I want disabled if a binding value is false or null. Here is was I tried.
<Button Content="Open" IsEnabled="{Binding SearchItem.WFBatchFolderStatus.UserCanOpen, Mode=OneWay, TargetNullValue=false, Converter={StaticResource booleanPassThru}}" />
I have a case in which SearchItem.WFBatchFolderStatus can be null (and for valid business reasons). If SearchItem.WFBatchFolderStatus is null then I want the button disabled. When SearchItem.WFBatchFolderStatus is null then the converter does not fire. If SearchItem.WFBatchFolderStatus is not null then the converter fires. The converter just returns false if the value is null and otherwise the the value. But the converter never sees a null. When SearchItem.WFBatchFolderStatus is null the button IS enabled (not what I want). If I remove the TargetValue and/or Converter then button is still enabled when SearchItem.WFBatchFolderStatus is null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果路径的一部分为空,则绑定失败,请设置
Binding.FallbackValue
设置为 false,如果WFBatchFolderStatus
为 null,则应禁用它。The binding fails if a part of the path is null, set the
Binding.FallbackValue
to false and it should be disabled ifWFBatchFolderStatus
is null.使用样式来代替怎么样?
How about using a style instead?