我正在使用RibbonControlLibrary中的Ribbon控件来处理.net 3.5。
我不能使用RibbonWindow
来解决一些表示兼容性问题。所以我将一个Ribbon控件放在Window
中。
没有明显的问题,但我在VisualStudio输出窗口中收到2条错误消息。
这些消息是:
- System.Windows.Data错误:4:无法找到绑定源,引用'RelativeSource FindAncestor,AncestorType ='Microsoft.Windows.Controls.Ribbon.RibbonWindow',AncestorLevel ='1''。 BindingExpression:路径=的WindowState;的DataItem = NULL; target元素是'Ribbon'(Name =''); target属性是'NoTarget'(类型'对象')
- System.Windows.Data错误:4:无法找到绑定源,引用'RelativeSource FindAncestor,AncestorType ='Microsoft.Windows.Controls.Ribbon.RibbonWindow',AncestorLevel ='1''。 BindingExpression:路径= IsActive;的DataItem = NULL; target元素是'Ribbon'(Name =''); target属性是'NoTarget'(类型'对象')
只需将Ribbon
添加到Window
并运行应用程序即可重现。
有没有办法告诉Ribbon不要尝试将任何内容完全绑定到RibbonWindow但是对于Window?
既然你说你不能使用RibbonWindow(出于某种原因......),我假设你正在做类似的事情
<Window x:Class="Yournamespace" ...>
<Ribbon>
</Ribbon>
</Window>
你的祖先应该是AncestorType='System.Windows.Window'
而不是'Microsoft.Windows.Controls.Ribbon.RibbonWindow'
你可能有:
<Window x:Class="yournamespace"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
...>
<r:Ribbon>
</r:Ribbon>
</Window>
To fix this just replace <Window> and </Window> with <r:RibbonWindow> and </r:RibbonWindow>
这为我修好了