简体   繁体   中英

insert Ribbon user controls WPF

I have an application that uses MetroWindow. I declare my MainWindow like this:

<MahApps:MetroWindow

And in MainWindow.xaml.cs :

public partial class MainWindow : MetroWindow

Now I want to integrate a ribbon menu in the application. I create a user control for the ribbon menu, and I integrate it in a page of my application.

<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>

When I run the application I get an exception in the InitializeComponent() of the ribbon user control. I think that I should change my main window to RibbonWindow :

In Mainwindow.xaml:

<RibbonWindow

In MainWindow.xaml.cs:

public partial class MainWindow : RibbonWindow

But visual studio is telling me that class"MainWindow" cannot have multiple base classes :'MetroWindow' and 'RibbonWindow'.

In addition to that, when I delete the RibbonTab from the ribbon UC it works.

Can someone help me ?

Something is still referencing MetroWindow controls. There is not enough code to tell you what though.

Make sure you are referencing the RibbonControlsLibrary. Try adding xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonCon‌​trolsLibrary" and then do

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM