none
WPF Ribbon - Quick Access Toolbar

    Question

  • I have a problem when the user right-clicks on a ribbon button and chooses "Add to Quick Access Toolbar" -- it throws the exception "No parameterless constructor defined for this object".  Has anyone had this problem?

     

    <rbn:Ribbon.Resources>
            <Style TargetType="{x:Type rbn:RibbonButton}">
              <Setter Property="CanAddToQuickAccessToolBarDirectly" Value="true"/>
              <Setter Property="ToolTipFooterImageSource" Value="Images\help_16x16.png"/>
              <Setter Property="ToolTipFooterTitle" Value="Press F1 for more help."/>
            </Style>
    </rbn:Ribbon.Resources>
    

    Friday, July 29, 2011 2:33 PM

Answers

  • The problem was that in the RibbonHelper CreateInstance method the return value is
    return (FrameworkElement)Activator.CreateInstance(original.GetType());
    

    When this method is called for the control being added to the QAT everything works fine.  However, this method is also called on the RibbonWindow when a control is added to the QAT through the context menu.  In my case, the RibbonWindow class does not have a parameterless constructor which makes the above return statement fail.  If you wish to add items to the QAT through the provided context menu, your RibbonWindow class must have a default parameterless constructor.  If not, you will have to replace the control's context menu with your own and handle the click event to add the item to the QAT.
    Wednesday, August 03, 2011 3:21 PM

All replies

  • Hi Michael.Laterza,

    I have not reproduced this exception "No parameterless constructor defined for this object", I create a simple sample, and "Add to Quick Access Toolbar" works well on "Ribbon close Button", the code as bellow:

       <ribbon:RibbonWindow x:Class="WpfRibbonApplication5.MainWindow"

            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"

            Title="MainWindow"

                            x:Name="RibbonWindow"

                            Width="640" Height="480">

        <Grid x:Name="LayoutRoot">

            <Grid.RowDefinitions>

                <RowDefinition Height="Auto"/>

                <RowDefinition Height="*"/>

            </Grid.RowDefinitions>

     

            <ribbon:Ribbon x:Name="Ribbon"  Background="BlanchedAlmond"  >

                <ribbon:Ribbon.ApplicationMenu>

                    <ribbon:RibbonApplicationMenu SmallImageSource="Images\Open.png" Background="Maroon" >

                        <ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"

                                                          x:Name="MenuItem1"

                                                          ImageSource="Images\LargeIcon.png"/>

                    </ribbon:RibbonApplicationMenu>

                </ribbon:Ribbon.ApplicationMenu>

                <ribbon:RibbonTab Header="Home">

                    <ribbon:RibbonGroup Header="Group1" QuickAccessToolBarId="{Binding Label}">

                        <ribbon:RibbonButton

                                             LargeImageSource="Images\LargeIcon.png"                                        

                                             Label="Button1" />

     

                        <ribbon:RibbonButton

                                             SmallImageSource="Images\SmallIcon.png"

                                             Command="Close"

                                             Label="Close" />

                        <ribbon:RibbonSplitButton

                                             SmallImageSource="Images\SmallIcon.png"

                                             Command="FirstPage"

                                             Label="Page Home" >

                            <ribbon:RibbonMenuItem Header="Next Page"

                                            ImageSource="{x:Null}"

                                            QuickAccessToolBarImageSource="Images\Plus.ico"

                                            Command="NextPage"/>

                            <ribbon:RibbonMenuItem Header="Previous Page"

                                            ImageSource="Images\Sign 05.ico"

                                            QuickAccessToolBarImageSource="Images\Minus.ico"

                                            Command="PreviousPage"/>

     

                        </ribbon:RibbonSplitButton>

                        <ribbon:RibbonButton

                                             SmallImageSource="Images\SmallIcon.png"

                            Command="Close"

                                             Label="Button4" />

                    </ribbon:RibbonGroup>

                </ribbon:RibbonTab>

            </ribbon:Ribbon>

        </Grid>

    </ribbon:RibbonWindow>

    Additional, there is a helpful blog you could refer to:

    http://blogs.msdn.com/b/llobo/archive/2010/08/06/wpf-ribbon-basics.aspx#comments

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 01, 2011 7:42 AM
  • The problem was that in the RibbonHelper CreateInstance method the return value is
    return (FrameworkElement)Activator.CreateInstance(original.GetType());
    

    When this method is called for the control being added to the QAT everything works fine.  However, this method is also called on the RibbonWindow when a control is added to the QAT through the context menu.  In my case, the RibbonWindow class does not have a parameterless constructor which makes the above return statement fail.  If you wish to add items to the QAT through the provided context menu, your RibbonWindow class must have a default parameterless constructor.  If not, you will have to replace the control's context menu with your own and handle the click event to add the item to the QAT.
    Wednesday, August 03, 2011 3:21 PM