A simple work around would be to simply replace <Window>
with <RibbonWindow>
and <Ribbon>
as the first child. Keep in mind that the Ribbon control is already integrated into .NET 4.5.
First edit your MainWindow.xaml
by replacing Window
with RibbonWindow
and add <Ribbon x:Name="Ribbon" Title="Ribbon Title">
.
Example:
<RibbonWindow x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
x:Name="RibbonWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Ribbon x:Name="Ribbon" Title="Ribbon Title">
...........
</Ribbon>
</Grid>
</RibbonWindow>
You will also need to edit the MainWindow.xaml.cs
to inherit the RibbonWindow
class instead of Window
.
public partial class MainWindow : RibbonWindow
Last remember to import the reference from the .NET Framework.
System.Windows.Controls.Ribbon
Edit: Update with solution for VB.Net
.
1) Add reference
- Right click on your project and choose
Add Reference
.
- Find
System.Windows.Controls.Ribbon
under Assemblies and Framework.
- Click
OK
to save.
2) Edit your MainWindow.xaml
- Back up any existing code.
- Replace the default template with the code in my Example.
- Add your new content within the
<Ribbon></Ribbon>
tag.
3) Edit your Mainwindow.xaml.vb
- Right click on
MainWindow.xaml
and click View Code
.
- Change
Class Window
to Class RibbonWindow
.
4) Run the program!