添加 RibbonGroup 时出现未处理的异常
我正在尝试在 WPF 应用程序中实现 Outlook 功能区,并且功能区工作正常。但是,当我尝试添加 RibbonGroup 时,我在 XAML 中遇到未处理的异常。
这是我的代码:
<r:RibbonWindow
x:Class="WpfArticles.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="Main" Height="500" Width="500">
<StackPanel>
<r:Ribbon Title="WPF Ribbon - Document1" x:Name="ribbon" >
<r:RibbonTab Label="Home">
<r:RibbonGroup Name="Test" />
</r:RibbonTab>
<r:RibbonTab Label="Insert"/>
<r:RibbonTab Label="Help"/>
</r:Ribbon >
并且我在 XAML 中收到此错误:
Object reference not set to an instance of an object. at
Microsoft.Windows.Controls.Ribbon.RibbonGroup.OnApplyTemplate() at
System.Windows.FrameworkElement.ApplyTemplate() at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.StackPanel.MeasureOverride(Size constraint) at
Microsoft.Windows.Controls.Ribbon.RibbonGroupsContainer.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.StackPanel.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Decorator.MeasureOverride(Size constraint) at
System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.DockPanel.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
MS.Internal.WindowControl.DesignTimeWindow.MeasureOverride(Size availableSize) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Designer.SimpleViewManager.DesignerBackground.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Decorator.MeasureOverride(Size constraint) at
Microsoft.Windows.Design.Interaction.DesignerView.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Designer.Viewport.MeasureOverride(Size availableSize) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Interop.HwndSource.SetLayoutSize() at
System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value) at
System.Windows.Interop.HwndSource.set_RootVisual(Visual value) at
MS.Internal.Designer.VSIsolatedDesigner.ViewHolder.Initialize() at
MS.Internal.Designer.VSIsolatedDesigner.ViewHolder..ctor(UIElement content) at
MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.get_ViewHandle() at
MS.Internal.Host.Isolation.IsolatedView.get_ViewHandle() at
MS.Internal.Designer.DesignerPane.LoadDesignerView()
我做错了什么?如果没有
它工作正常!
感谢您的帮助和时间
I am trying to implement the Outlook Ribbon in a WPF application, and the ribbon works fine. However when I try to add a RibbonGroup, I get an unhandled exception in the XAML.
Here is my code:
<r:RibbonWindow
x:Class="WpfArticles.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="Main" Height="500" Width="500">
<StackPanel>
<r:Ribbon Title="WPF Ribbon - Document1" x:Name="ribbon" >
<r:RibbonTab Label="Home">
<r:RibbonGroup Name="Test" />
</r:RibbonTab>
<r:RibbonTab Label="Insert"/>
<r:RibbonTab Label="Help"/>
</r:Ribbon >
and I am getting this error in the XAML :
Object reference not set to an instance of an object. at
Microsoft.Windows.Controls.Ribbon.RibbonGroup.OnApplyTemplate() at
System.Windows.FrameworkElement.ApplyTemplate() at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.StackPanel.MeasureOverride(Size constraint) at
Microsoft.Windows.Controls.Ribbon.RibbonGroupsContainer.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.StackPanel.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Decorator.MeasureOverride(Size constraint) at
System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.DockPanel.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Border.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
MS.Internal.WindowControl.DesignTimeWindow.MeasureOverride(Size availableSize) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Designer.SimpleViewManager.DesignerBackground.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Decorator.MeasureOverride(Size constraint) at
Microsoft.Windows.Design.Interaction.DesignerView.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Designer.Viewport.MeasureOverride(Size availableSize) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Grid.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at
System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Controls.Control.MeasureOverride(Size constraint) at
System.Windows.FrameworkElement.MeasureCore(Size availableSize) at
System.Windows.UIElement.Measure(Size availableSize) at
System.Windows.Interop.HwndSource.SetLayoutSize() at
System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value) at
System.Windows.Interop.HwndSource.set_RootVisual(Visual value) at
MS.Internal.Designer.VSIsolatedDesigner.ViewHolder.Initialize() at
MS.Internal.Designer.VSIsolatedDesigner.ViewHolder..ctor(UIElement content) at
MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.get_ViewHandle() at
MS.Internal.Host.Isolation.IsolatedView.get_ViewHandle() at
MS.Internal.Designer.DesignerPane.LoadDesignerView()
What am I doing wrong? Without the <r:RibbonGroup Name="Test" />
it works fine!
Thanks for your help and time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您使用的是旧版本,因为 Label 属性不再有效。可以找到最新版本 这里。
I suspect you are using an older version, as the Label property is no longer valid. The latest version can be found here.
我下载了该功能区,但由于某种原因无法添加参考。无论如何,我下载了一个示例,它明确表示如果该组为空,则会抛出异常。所以现在一切正常。感谢您的帮助!
I downloaded that ribbon but could not add the reference for some reason. Anyway, I downloaded an example and it clearly said that the Group will throw an exception if it is empty. So now everything works fine. Thanks for your help!