【发布时间】:2016-05-22 10:55:54
【问题描述】:
我有一个使用 MetroWindow 的应用程序。 我这样声明我的 MainWindow:
<MahApps:MetroWindow
在 MainWindow.xaml.cs 中:
public partial class MainWindow : MetroWindow
现在我想在应用程序中集成一个功能区菜单。 我为功能区菜单创建了一个用户控件,并将它集成到我的应用程序页面中。
<UserControl x:Class="Nine.Views.Controls.RibbonBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Nine.Views.Controls"
mc:Ignorable="d"
Height="120.213" Width="1263.298">
<!-- menu bar-->
<Grid>
<Ribbon >
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu >
<RibbonApplicationMenuItem Header="Bonjour" />
<RibbonSeparator />
<RibbonApplicationMenuItem Header="Exit" Command="Close" />
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<RibbonTab Header="Home">
<RibbonGroup Header="Clipboard">
<RibbonButton Command="Paste" Label="Paste"
LargeImageSource="Images/paste.png" />
<RibbonButton Command="Cut" SmallImageSource="Images/cut.png" />
<RibbonButton Command="Copy" SmallImageSource="Images/copy.png" />
<RibbonButton Command="Undo" LargeImageSource="Images/undo.png" />
</RibbonGroup>
</RibbonTab>
</Ribbon>
</Grid>
当我运行应用程序时,功能区用户控件的 InitializeComponent() 中出现异常。 我认为我应该将主窗口更改为 RibbonWindow :
在 Mainwindow.xaml 中:
<RibbonWindow
在 MainWindow.xaml.cs 中:
public partial class MainWindow : RibbonWindow
但 Visual Studio 告诉我“MainWindow”类不能有多个基类:“MetroWindow”和“RibbonWindow”。
除此之外,当我从功能区 UC 中删除 RibbonTab 时,它可以工作。
有人可以帮助我吗?
【问题讨论】:
-
您的 XAML 和您的代码隐藏必须与您的窗口类型一致,
MetroWindow或RibbonWindow,否则您会收到 多个基类 警告。 -
那么我该如何解决这个问题呢?在我的应用程序中,我想同时使用 Ribbon 和 Metro。我可以从集成 Ribbon UserControl 的页面中引用 Ribbon 吗?