将功能区文本框 IsEnabled 绑定到复选框 IsChecked 不起作用

发布于 2025-01-01 17:50:03 字数 1229 浏览 6 评论 0原文

下面是示例 XAML:

...
<ribbon:RibbonTab Header="MyTab">
  <ribbon:RibbonGroup Header="Blah">
    <ribbon:RibbonTextBox x:Name="MyTextBox" 
                          IsEnabled="{Binding IsChecked, ElementName=MyCheckBox}" />
    <ribbon:RibbonCheckBox x:Name="MyCheckBox" Label="some text" />
  </ribbon:RibbonGroup>
</ribbon:RibbonTab>
...

由于某种原因,无论是否选中该复选框,文本框都保持禁用状态。为什么绑定不能正常工作?

您可以将上面的代码减去顶部和底部的省略号添加到样板 WPF 功能区项目中,看看是否可以找出问题所在。例如,我没有看到任何绑定错误诊断。

更新:如果用常规TextBox 替换RibbonTextBox,则行为将变得正确。我的结论是,绑定 RibbonTextBox 的 IsEnabled 属性一定存在一些问题。

奇怪的更新 #2:创建一个基本的 RibbonTextBox 并将其 IsEnabled 属性设置为 True 创建一个禁用的 RibbonTextBox。什么给?

我已提交 Microsoft Connect 上的错误报告,以进一步解决此问题。

最终更新已在 WPF 4.5 中修复

Here is the sample XAML:

...
<ribbon:RibbonTab Header="MyTab">
  <ribbon:RibbonGroup Header="Blah">
    <ribbon:RibbonTextBox x:Name="MyTextBox" 
                          IsEnabled="{Binding IsChecked, ElementName=MyCheckBox}" />
    <ribbon:RibbonCheckBox x:Name="MyCheckBox" Label="some text" />
  </ribbon:RibbonGroup>
</ribbon:RibbonTab>
...

For some reason, the text box stays disabled regardless of whether or not the check box is checked. Why is the binding not working properly?

You can add the above code minus the elipses at the top and bottom to a boiler plate WPF ribbon project and see if you can figure out what's wrong. I see no binding error diagnostics, for example.

Update: If a regular TextBox is substituted for the RibbonTextBox, the behavior becomes correct. I conclude that there must be some issue with binding the IsEnabled property of a RibbonTextBox.

Freaky update #2: Creating a basic RibbonTextBox and setting its IsEnabled property to True creates a disabled RibbonTextBox. What gives?

I have submitted a bug report on Microsoft Connect to further pursue this issue.

Final update: It's fixed in WPF 4.5.

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

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

发布评论

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

评论(1

人生百味 2025-01-08 17:50:03

作为一个大胆的猜测,您是否尝试过完全鉴定该房产?

IsEnabled="{Binding RibbonCheckBox.IsChecked, ElementName=MyCheckBox}" 

...或者甚至...

IsEnabled="{Binding CheckBox.IsChecked, ElementName=MyCheckBox}" 

As a wild guess, have you tried fully qualifying the property?

IsEnabled="{Binding RibbonCheckBox.IsChecked, ElementName=MyCheckBox}" 

... or maybe even...

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