This is a migrated thread and some comments may be shown as answers.

RibbonView and MVVM

3 Answers 208 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 04 May 2012, 07:10 PM
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.


3 Answers, 1 is accepted

Sort by
0
Eric
Top achievements
Rank 1
answered on 04 May 2012, 10:47 PM
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?

0
Eric
Top achievements
Rank 1
answered on 07 May 2012, 05:00 PM
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 :)
0
Tina Stancheva
Telerik team
answered on 08 May 2012, 07:52 PM
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 >>

Tags
RibbonView and RibbonWindow
Asked by
Eric
Top achievements
Rank 1
Answers by
Eric
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or