Reuse RadRibbonGroup

4 posts, 0 answers
  1. Manuel
    Manuel avatar
    43 posts
    Member since:
    Jul 2010

    Posted 25 Jul 2013 Link to this post

    Hello,

    in many menus I use the same buttons.
    Is it possible to create a kind of a base class?

    In this case it would be nice to have a base class of the complete group header "actions".

    eg:

    <telerik:RadRibbonView ApplicationButtonVisibility="Collapsed"TitleBarVisibility="Collapsed" HelpButtonVisibility="Collapsed">
                <telerik:RadRibbonTab Header="Home" HeaderVisibility="Collapsed">
                    <telerik:RadRibbonGroup Header="Actions">
                        <telerik:RadRibbonButton LargeImage="{StaticResource Back}" Text="Close" Size="Large"
                                                          Command="{Binding CloseViewCommand}" />
                        <telerik:RadRibbonButton LargeImage="{StaticResource Edit}" Text="Edit" Size="Large"
                                                          Command="{Binding EditItemCommand}" />
                        <telerik:RadRibbonButton LargeImage="{StaticResource Save}" Text="Save" Size="Large"
                                                          Command="{Binding SaveItemCommand}" />
                        <telerik:RadRibbonButton SmallImage="{StaticResource Cancel}" Text="Cancel" Size="Large"
                                                          Command="{Binding CancelItemCommand}" />
                    </telerik:RadRibbonGroup>
     
                    <telerik:RadRibbonGroup Header="Print">
                        <telerik:RadRibbonButton SmallImage="{StaticResource Print}"  Text="xxx" Size="Large"
                                                          Command="{Binding PrintItemCommand}"/>
                    </telerik:RadRibbonGroup>
     
                    <telerik:RadRibbonGroup Header="Extras">
                        <telerik:RadRibbonButton SmallImage="{StaticResource UpdatePortrait}"  Text="xxxxx" Size="Large"
                                                          Command="{Binding UpdatePictureCommand}"/>
                    </telerik:RadRibbonGroup>
                </telerik:RadRibbonTab>
            </telerik:RadRibbonView>


    Thank you,
    Manuel
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 30 Jul 2013 Link to this post

    Hello Manuel,

    As far as I understand your scenario you want to reuse exactly the same RadRibbonGroup (in your snippet called "Actions"). You can achieve your requirement by creating a custom UserControl that will derive from our RadRibbonGroup class and define your RadRibbonButtons in it. Furthermore, you can use your UserControl instead of RadRibbonGroup.

    For your convenience I implemented this approach in the attached project. Please take a look at it and let me know if it works for you.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Manuel
    Manuel avatar
    43 posts
    Member since:
    Jul 2010

    Posted 30 Jul 2013 Link to this post

    Hi Pavel,

    thanks for your help. it is woking!

    Now i have another idea but i cannot get it to work.
    Error: Specified element is already the logical child of another element. Disconnect it first.

    I like to place the "default buttons" and a ContentPresenter in a RadRibbenTab.
    The content of the ContentPresenter is bound to a dependency property.
    the Idea is to have a complete base class of the RibbenTab, the goal is to put only the required RadRibbonButtons / RadRibbonGroups in it.

    <telerik:RadRibbonView....                     
    ApplicationButtonVisibility="Collapsed"
                        
    xmlns:local="clr-namespace:Tortuga.Controls.Core"
                                        
     TitleBarVisibility="Collapsed" HelpButtonVisibility="Collapsed">
             
    <
    telerik:RadRibbonTab Header="Home" HeaderVisibility="Collapsed">        
    <
    local:DefaultButtons />      
    <
    ContentPresenter Content="{Binding Content}" /> 
     
    </
    telerik:RadRibbonTab>
    </
    telerik:RadRibbonView>


    public partial class DetailsMenu : RadRibbonView
        {
           
    public DetailsMenu()
            {
                InitializeComponent();
            }
           
    public FrameworkElement Content
            {
              
    get { return (FrameworkElement)GetValue(ContentProperty); }
               
    set { SetValue(ContentProperty, value); }
            }
           
    public static readonly DependencyProperty ContentProperty =
                DependencyProperty.Register(
    "Content", typeof(FrameworkElement), typeof(DetailsMenu), new PropertyMetadata(null));
     
        }

    Impelmentation:
            <local:DetailsMenu>
                <
    local:DetailsMenu.MyContent>
                    <
    local:SpecificButtons/>
                </
    local:DetailsMenu.MyContent>
            </local:DetailsMenu>

    Thank you,
    Manuel
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 02 Aug 2013 Link to this post

    Hi Manuel,

    As I can see in your code you create a custom user control which derives from our RadRibbonView control. Furthermore, you expose a Content property and now your requirement is to visualize that content. You need to have in mind that when you create a custom Control with custom properties in it, you also need to define a custom ControlTemplate that will define how your properties will be visualized. Please note that the RadRibbonView do not expose Content property and this is why your content will not be visualized.

    Maybe you need to derive only the RadRibbonGroup and define the Content property in it. Furthermore, you will have to extract its default ControlTemplate and customize it. You can replace the ItemsPresenter (defined in the ControlTemplate) with a ContentPresenter and bind its Content to your custom property. Also, please note that you will be able to define all the buttons that you need to reuse in the same ControlTemplate.

    Let me now get to the error that you report. Such error may be caused by the fact that elements with the same (x:)Name property exist more than once in your application. Please make sure that there are no (x:)Name properties set.

    On the other hand, you can consider using an MVVM approach in your application. For more information you can take a look at our online demonstration project.

    For your convenience I implemented the approach with the derived RadRibbonGroup in the attached project. Also, you will be able to find a basic implementation of the MVVM approach that can be used as a start up project. Please take a look at the attached project and let me know if it works for you.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top