WPF apps .Core 3.0 and microsoft ribbon control library 4.0

2.6k Views Asked by At

Hello I tried to build an application using the WPF,.Netcore 3.0 and microsoft ribbon control library 4.0 and it's failed.

I need help or an example on the web. I did look at Microsoft WPF-Sample on GitHub but did not find a ribbon sample working on .netcore 3.0

MainWindow.Xaml

<Window x:Class="WpfDoNetcore3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
        xmlns:local="clr-namespace:WpfDoNetcore3"
        mc:Ignorable="d"
        x:Name="RibbonWindow"
        Title="MainWindow" Height="450" Width="800">

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ribbon:Ribbon x:Name="Ribbon" Title="Ribbon Title">
            <ribbon:Ribbon.HelpPaneContent>
                <ribbon:RibbonButton SmallImageSource="Images\Smallicon.png" />
            </ribbon:Ribbon.HelpPaneContent>
            <ribbon:Ribbon.QuickAccessToolBar>
                <ribbon:RibbonQuickAccessToolBar >
                    <ribbon:RibbonButton x:Name="QATButton1" 
                                         SmallImageSource="Images\Smallicon.png" />
                    <ribbon:RibbonButton x:Name="QATButton2" 
                                         SmallImageSource="Images\Smallicon.png" />
                </ribbon:RibbonQuickAccessToolBar>
            </ribbon:Ribbon.QuickAccessToolBar>
            <ribbon:Ribbon.ApplicationMenu>
                <ribbon:RibbonApplicationMenu SmallImageSource="Images\Smallicon.png">
                    <ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"
                                                      x:Name="MenuItem1"
                                                      ImageSource="Images\Largeicon.png"/>
                </ribbon:RibbonApplicationMenu>
            </ribbon:Ribbon.ApplicationMenu>
            <ribbon:RibbonTab x:Name="HomeTab" 
                              Header="Home">
                <ribbon:RibbonGroup x:Name="Group1" 
                                    Header="Group1">
                    <ribbon:RibbonButton x:Name="Button1"
                                         LargeImageSource="Images\Largeicon.png"
                                         Label="Button1" />
                    <ribbon:RibbonButton x:Name="Button2"
                                         SmallImageSource="Images\Smallicon.png"
                                         Label="Button2" />
                    <ribbon:RibbonButton x:Name="Button3"
                                         SmallImageSource="Images\Smallicon.png"
                                         Label="Button3" />
                    <ribbon:RibbonButton x:Name="Button4"
                                         SmallImageSource="Images\Smallicon.png"
                                         Label="Button4" />
                </ribbon:RibbonGroup>
            </ribbon:RibbonTab>
        </ribbon:Ribbon>
    </Grid>

</Window>

Mainwindow.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Ribbon;

namespace WpfDoNetcore3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {


            InitializeComponent();
        }
    }
}

Ref: Github project

1

There are 1 best solutions below

1
On BEST ANSWER

Just remove the xmlns:ribbon namespace declaration and the ribbon: prefix from your XAML and try to build:

<Window x:Class="WpfDoNetcore3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        x:Name="RibbonWindow"
        Title="MainWindow" Height="450" Width="800">
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Ribbon x:Name="Ribbon" Title="Ribbon Title">
            <Ribbon.HelpPaneContent>
                <RibbonButton SmallImageSource="Images\Smallicon.png" />
            </Ribbon.HelpPaneContent>
            <Ribbon.QuickAccessToolBar>
                <RibbonQuickAccessToolBar >
                    <RibbonButton x:Name="QATButton1" 
                                         SmallImageSource="Images\Smallicon.png" />
                    <RibbonButton x:Name="QATButton2" 
                                         SmallImageSource="Images\Smallicon.png" />
                </RibbonQuickAccessToolBar>
            </Ribbon.QuickAccessToolBar>
            <Ribbon.ApplicationMenu>
                <RibbonApplicationMenu SmallImageSource="Images\Smallicon.png">
                    <RibbonApplicationMenuItem Header="Hello _Ribbon"
                                                      x:Name="MenuItem1"
                                                      ImageSource="Images\Largeicon.png"/>
                </RibbonApplicationMenu>
            </Ribbon.ApplicationMenu>
            <RibbonTab x:Name="HomeTab" 
                              Header="Home">
                <RibbonGroup x:Name="Group1" 
                                    Header="Group1">
                    <RibbonButton x:Name="Button1"
                                         LargeImageSource="Images\Largeicon.png"
                                         Label="Button1" />
                    <RibbonButton x:Name="Button2"
                                         SmallImageSource="Images\Smallicon.png"
                                         Label="Button2" />
                    <RibbonButton x:Name="Button3"
                                         SmallImageSource="Images\Smallicon.png"
                                         Label="Button3" />
                    <RibbonButton x:Name="Button4"
                                         SmallImageSource="Images\Smallicon.png"
                                         Label="Button4" />
                </RibbonGroup>
            </RibbonTab>
        </Ribbon>
    </Grid>

</Window>

This should work. The Ribbon controls have been part of the WPF itself since .NET Framework 4.5, so you don't have to reference and use any external library if you target Framework 4.5+ or .NET Core 3+.