插入功能区用户控件WPF

时间:2016-02-11 15:19:00

标签: c# wpf xaml ribbon

我有一个使用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时,它可以正常工作。

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

还有一些东西仍在引用MetroWindow控件。没有足够的代码告诉你什么。

确保您引用了RibbonControlsLibrary。尝试添加xmlns:ribbon =“clr-namespace:Microsoft.Windows.Controls.Ribbon; assembly = RibbonCon trolsLibrary”然后再做

相关问题