RibbonView and MVVM

4 posts, 0 answers
  1. Eric
    Eric avatar
    6 posts
    Member since:
    Dec 2011

    Posted 04 May 2012 Link to this post

    Hi All,

    I have a few classes that define the datacontext for controls in the RibbonView:

    public class RibbonElement
    {
        public string Text { get; set; }
        public bool IsEnabled { get; set; }
    }
     
    public class Tab : RibbonElement
    {
        public ObservableCollection<Group> Groups { get; set; }
    }
     
    public class Group : RibbonElement
    {
        public ObservableCollection<Button> Buttons { get; set; }
    }
     
    public class Button : RibbonElement
    {
    }

    And I have several HierarchicalDataTemplates that define how the classes are visualized (modeled after the samples on this site):

        <DataTemplate x:Key="ButtonTemplate">
                <t:RadRibbonButton Text='{Binding Text}' IsEnabled='{Binding IsEnabled}' />
        </DataTemplate>
     
        <HierarchicalDataTemplate x:Key="GroupTemplate"
                                  ItemsSource='{Binding Buttons}'
                                  ItemTemplate='{StaticResource ButtonTemplate}'>
            <TextBlock Text='{Binding Text}' /> 
        </HierarchicalDataTemplate>
     
        <HierarchicalDataTemplate x:Key="TabTemplate"
                                  ItemsSource='{Binding Groups}'
                                  ItemTemplate='{StaticResource GroupTemplate}'>
            <TextBlock Text='{Binding Text}' />
        </HierarchicalDataTemplate>
    </Window.Resources>
     
    <t:RadRibbonView ItemsSource='{Binding Tabs}'
                     ItemTemplate='{StaticResource TabTemplate}'
                     ApplicationButtonVisibility="Hidden" />

    How can I create the RadRibbonGroup/RadRibbonTab controls in the templates, instead of using a TextBlock?  I need to do this so that I can bind to IsEnabled to dynamically enable/disable groups.   The RadRibbonTab seems to take the output of the template and put it in the group header instead of the actual RadRibbonGroup control.   By contrast, the headered controls in the rest of WPF have HeaderTemplate property for headers and ItemTemplate property for items.


  2. Eric
    Eric avatar
    6 posts
    Member since:
    Dec 2011

    Posted 04 May 2012 Link to this post

    I just used the Microsoft Ribbon for WPF and it does the same thing.  So I guess it's the underlying Microsoft control that does it. 

    Anyone know how to get around this?

  3. UI for WPF is Visual Studio 2017 Ready
  4. Eric
    Eric avatar
    6 posts
    Member since:
    Dec 2011

    Posted 07 May 2012 Link to this post

    In case this helps anyone who is also struggling with this issue:  I was able to use the ItemContainerStyle to bind to IsEnabled.

    <HierarchicalDataTemplate x:Key='TabTemplate'
                              ItemsSource='{Binding Groups}'
                              ItemTemplate='{StaticResource GroupTemplate}'>
        <HierarchicalDataTemplate.ItemContainerStyle>
            <Style TargetType="{x:Type r:RibbonGroup}">
                <Setter Property='IsEnabled'
                        Value="{Binding IsEnabled}" />
            </Style>
        </HierarchicalDataTemplate.ItemContainerStyle>
        <TextBlock Text='{Binding Text}' />
    </HierarchicalDataTemplate>

    Seems like (to my mind, anyway) that the internals of the Microsoft Ribbon Control for WPF are structured in a rather strange way, unlike any other items containers.  Maybe I'm just missing something.   But, as long as there is a way to work around it, I'm happy :)
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 08 May 2012 Link to this post

    Hi Eric,

    The RadRibbonView control is a data-driven hierarchical items control which allows you to use HierarchicalDataTemplates in order to define the way the RibbonTabs, RibbonGroups displayed. And in a databinding scenario it is important to note that the RadRibbonView generates automatically a collection of RibbonTab and RibbonGroup containers to wrap the business items. And this is why the DataTemplates allow you only to control the way the business data will be displayed inside the generated containers and for all RibbonTab/RibbonGroup properties, you can use Style bindings. The approach used in the RibbonView controls is similar to the approach used in an ItemsControls like the (Rad)TreeView or (Rad)TabControl.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top