I'm new in WPF and I would like to create a reusable base menu ribbon (System.Windows.Controls.Ribbon). My purpose is to create the base structure of ribbon menu (Ribbon.QuickAccessToolBar + Ribbon.ApplicationMenu) that is shared from all application. But I'd like to have different usercontrol child that add different elements to the base menu (es RibbonTab + RibbonButton etc..). In other post suggest me to use ResourceDictionary for purpose. So I try to use ResourceDictionary. If I test the method with simple buttons control it works as I expect.
But if instead use Button Class I use RibbonTab class i don't have the same result.
Can anything help me? Thank you very much.
What I have tried:
I've tried with button:
Dictionary3.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestUserControl"
xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon">
<Style TargetType="{x:Type local:TestBaseControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:TestBaseControl}">
<StackPanel>
<Button>Btn1</Button>
<ContentPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
UserControlChild2.xaml
<local:TestBaseControl x:Class="TestUserControl.UserControlChild2"
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:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
xmlns:local="clr-namespace:TestUserControl"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<local:TestBaseControl.Resources>
<ResourceDictionary Source = "ResourceDictionaries/Dictionary3.xaml" />
</local:TestBaseControl.Resources>
<StackPanel>
<Button>Btn2</Button>
</StackPanel>
</local:TestBaseControl>
And works correctly. But i I try with RibbonTab:
Dictionary3.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestUserControl"
xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon">
<Style TargetType="{x:Type local:TestBaseControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:TestBaseControl}">
<StackPanel>
<ribbon:Ribbon>
<ribbon:RibbonTab Header="Home1"></ribbon:RibbonTab>
<ContentPresenter/>
</ribbon:Ribbon>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
UserControlChild2.xaml
<local:TestBaseControl x:Class="TestUserControl.UserControlChild2"
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:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
xmlns:local="clr-namespace:TestUserControl"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<local:TestBaseControl.Resources>
<ResourceDictionary Source = "ResourceDictionaries/Dictionary3.xaml" />
</local:TestBaseControl.Resources>
<StackPanel>
<ribbon:RibbonTab Header="Home2"></ribbon:RibbonTab>
</StackPanel>
</local:TestBaseControl>
Doesn't work correctly.