Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
(Urgent)how to write??RibbonGroup as a reusable resource
posted

Hi,

I have different tabs in Ribbon,

I have a File RibbonGroup, which is common across tabs

Is there anyway to make ribbon shared across tabs?

if not, reuable style resource like..

<Window.Resources>

<Style TargetType={x:Type igRibbon:RibbonGroup}>

<Setter Property="Items">  <!-- not sure what to put here as property-->

<Setter.Value>

<igRibbon:ToolVerticalWrap>......

</style>

 

 

 

  • 54937
    Suggested Answer
    Offline posted

    You cannot define an itemscontrol (which the RibbonGroup is) in that way and be able to populate the Items collection. The way to do this would be to define a xaml file that defines a RibbonGroup and then use the Application.LoadComponent method to new up an instance of it at runtime.  e.g. create a file named CommonRibbonGroup.xaml with the following content

    <igRibbon:RibbonGroup xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:igRibbon="http://infragistics.com/Ribbon"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <igRibbon:ButtonTool Caption="First" />
        <igRibbon:ButtonTool Caption="Second" />
    </igRibbon:RibbonGroup>

    Then at runtime you could instantiate instances of that uses the Application.LoadComponent method. e.g.

    Uri relativeGroupUri = new Uri("/CommonRibbonGroup.xaml"UriKind.Relative);
    AddRibbonGroup(this.tabA, 0, relativeGroupUri);
    AddRibbonGroup(this.tabB, 0, relativeGroupUri);
    AddRibbonGroup(this.tabC, 0, relativeGroupUri);
    }
     
    private static void AddRibbonGroup(RibbonTabItem tab, int preferredIndex, Uri ribbonGroupUri)
    {
    RibbonGroup group = (RibbonGroup)Application.LoadComponent(ribbonGroupUri);
     
    int index = Math.Max(0, Math.Min(preferredIndex, tab.RibbonGroups.Count));
    tab.RibbonGroups.Insert(index, group);
    }

     

    Alternatively you could derive a class from RibbonGroup and create instances of that instead of using LoadComponent but then the class will not follow the styling of the other elements if you set the Theme since in WPF a local style is always located based on the type name which in that case would be your derived type.