Click here to Skip to main content
15,885,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 11-Jan-20 21:31pm

1 solution

Your first example had a button "in the template"; the second does not. You're not comparing the same things.
 
Share this answer
 
Comments
Member 14711897 12-Jan-20 15:05pm    
Yes. I know. My purpose is to work with the ribbon Tab. I don't know how to do this thing with RibbonTab.
How can I do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900