Ribbon CommandBindings (Designer Problem)

Nov 4, 2008 at 9:24 AM
Any help would be appreciated - I've been trying to fix this for a couple of days now.

I installed all the prerequisites and got all the needed assemblies and I'm trying to go over the Ribbon part of the hands-on lab (exercise2).

When I open exercise2/final/CheckbookManager.sln and build it everything is fine and I can launch the application no problems. The problem comes when I try to edit the MainWindow.xaml file because it refuses to show up properly in the designer. The error I get is:

Error 1 Value 'me:AppCommands.AddNew' cannot be assigned to property 'Command'. 'CommandValueSerializer' ValueSerializer cannot convert from 'System.String'.    D:\WPFFeaturesPreviewHOLOnline\WPF Features Preview HOL Online - Source\source\exercise2\final\CheckbookManager\MainWindow.xaml    14    25    CheckbookManager
This happens at this line (and every other binding lines):
<CommandBinding Command="me:AppCommands.AddNew" Executed="OnAddNewEntry" />

I tried everything... and it seems the problem is with using a ResourceDictionary in AppCommands.xaml to define the RibbonCommands instead of just creating them from scratch.

I tried using this in AppCommands.cs:
public static RibbonCommand AddNew
{
    get { return new RibbonCommand( "Add New", typeof(AppCommands) ); }
}
Instead of this:
public static RibbonCommand AddNew
{
     get { return (RibbonCommand)Application.Current.Resources["AddNewCommand"]; }
}
And the problem disappeared (but went on to the next binding, which still uses the old method).

What's happening there? Why am I the only one getting this error?

Nov 4, 2008 at 11:32 AM
Hi,

You're not alone! I have the same problem, it's just not too high up my priority list at the moment, but I would also like to know why this is happening.


Nov 5, 2008 at 12:12 AM
Maybe the devs can shed some light on this?
Nov 5, 2008 at 5:02 AM
I decided to use this work-around, which makes AppCommands.cs useless and references the r:RibbonCommands in AppCommands.xaml directly using StaticResource. I'm just starting with WPF so I'm not sure what are the drawbacks of this workaround. Any comments on this workaround are appreciated:

<CommandBinding Command="{StaticResource AddNewCommand}" Executed="OnAddNewEntry" />
Nov 5, 2008 at 10:33 AM
i also did it in that manner:
<CommandBinding Command="{StaticResource NewCommand}" Executed="OnNew" />

seems to work fine...
any comments from the dev-team?

Coordinator
Nov 5, 2008 at 6:12 PM

Hey guys,

You're seeing this issue because

<CommandBinding Command="me:AppCommands.AddNew" Executed="OnAddNewEntry" />

refers to the following code:

public static RibbonCommand AddNew
{
     get { return (RibbonCommand)Application.Current.Resources["AddNewCommand"]; }
}

 

and at design time, Application.Current doesn’t refer to the runtime application but to the designtime application. This is a limitation of the VS designer and I believe it also applies to Blend.  We'll fix this in an upcoming iteration of the lab by moving all of the RibbonCommands from AppCommands.xaml into the resources of the window in MainWindow.xaml and updating the Ribbon controls to look for those commands.  For now, the workarounds you found should work fine.

Thanks for reporting this issue!
Samantha

Nov 27, 2008 at 2:04 PM
Hello together,

I have the same problems but using VB.Net and I don't get it fixed.
Could please someone tell me, where to put what to have buttons in a button group with an icon and so on and calling a procedure like

 

Private Sub RibbonControl_Cut(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

 

 

End Sub
in Windows1.xaml.vb

I have

 

 

 

<r:Ribbon DockPanel.Dock="Top" Grid.ColumnSpan="3" Title="BusinessBeansEditor">

 

 

 

 

 

 

<r:Ribbon.Resources>

 

 

 

 

 

 

<r:RibbonGroupSizeDefinitionCollection x:Key="RibbonLayout">

 

 

 

 

 

 

<r:RibbonGroupSizeDefinition>

 

 

 

 

 

 

<!-- Control sizes: L,L,L -->

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>

 

 

 

 

 

 

</r:RibbonGroupSizeDefinition>

 

 

 

 

 

 

<r:RibbonGroupSizeDefinition>

 

 

 

 

 

 

<!-- Control sizes: L,M,M -->

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"/>

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"/>

 

 

 

 

 

 

</r:RibbonGroupSizeDefinition>

 

 

 

 

 

 

<r:RibbonGroupSizeDefinition>

 

 

 

 

 

 

<!-- Control sizes: L,S,S -->

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False"/>

 

 

 

 

 

 

<r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False"/>

 

 

 

 

 

 

</r:RibbonGroupSizeDefinition>

 

 

 

 

 

 

<!-- Collapsed -->

 

 

 

 

 

 

<r:RibbonGroupSizeDefinition IsCollapsed="True" />

 

 

 

 

 

 

</r:RibbonGroupSizeDefinitionCollection>

 

 

 

 

 

 

</r:Ribbon.Resources>

 

 

 

 

 

 

<r:RibbonTab Label="Allgemein">

 

 

 

 

 

 

<r:RibbonTab.Groups>

 

 

 

 

 

 

<!-- Clipboard commands -->

 

 

 

 

 

 

<r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}">

 

 

 

 

 

 

<r:RibbonGroup.Command>

 

 

 

 

 

 

<r:RibbonCommand LabelTitle="Clipboard" SmallImageSource="images/Paste.png" />

 

 

 

 

 

 

</r:RibbonGroup.Command>

 

 

 

 

 

 

<r:RibbonButton/>

 

 

 

 

 

 

<r:RibbonButton/>

 

 

 

 

 

 

<r:RibbonButton/>

 

 

 

 

 

 

</r:RibbonGroup>

 

 

 

 

 

 

</r:RibbonTab.Groups>

 

 

 

 

 

 

</r:RibbonTab>

 

 

 

 

 

 

<r:RibbonTab Label="Grafik">

 

 

 

 

 

 

</r:RibbonTab>

 

 

 

 

 

 

<r:Ribbon.ApplicationMenu>

 

 

 

 

 

 

<r:RibbonApplicationMenu>

 

 

 

 

 

 

<r:RibbonApplicationMenu.Command>

 

 

 

 

 

 

<r:RibbonCommand

 

 

Executed="OnCloseApplication"

 

 

 

 

 

LabelTitle="Application Button"

 

 

 

 

 

LabelDescription="BusinessBeansEditor beenden."

 

 

 

 

 

SmallImageSource="/WpfTest;component/Resources/BBEditor.png"

 

 

LargeImageSource="/WpfTest;component/Resources/BBEditor.png"

 

 

 

 

 

ToolTipTitle="BusinessBeansEditor"

 

 

 

 

 

ToolTipDescription="Klicken Sie hier, um ein BusinessBean zu ”ffnen oder anzulegen" />

 

 

 

 

 

 

</r:RibbonApplicationMenu.Command>

 

 

 

 

 

 

 

<r:RibbonApplicationMenuItem>

 

 

 

 

 

 

<r:RibbonApplicationMenuItem.Command>

 

 

 

 

 

 

<r:RibbonCommand

 

 

LabelTitle="_Schliessen"

 

 

LabelDescription="BusinessBeansEditor beenden"

 

 

 

 

 

Executed="OnCloseApplication" />

 

 

 

 

 

 

</r:RibbonApplicationMenuItem.Command>

 

 

 

 

 

 

</r:RibbonApplicationMenuItem>

 

 

 

 

 

 

</r:RibbonApplicationMenu>

 

 

 

 

 

 

</r:Ribbon.ApplicationMenu>

 

 

 

 

 

 

</r:Ribbon>


in Window1.xaml

Regards
--
Carsten

Dec 1, 2008 at 6:45 PM
The StaticResource approach worked for me thanks! but i hope someday that resource lookup approach in the HOL works
Mar 23, 2009 at 11:30 AM
Edited Mar 23, 2009 at 12:04 PM

HI! Need help with the Ribbon Bar.

Problem : Ribbon Buttons is not enabled, its in a disable mode.

I'm able to the it working in terms of adding button, images and events etc.

My Code:

App.xaml

 

<r:RibbonCommand x:Key="AddNewCommand"
LabelTitle="New Item"
ToolTipTitle="Add New Item"
ToolTipDescription="Add New Stores Item"
SmallImageSource="RibbonImages/AddNew.png"
LargeImageSource="RibbonImages/AddNew.png"
ToolTipImageSource="RibbonImages/AddNew.png"/>
</r:Ribbon.Resources>

Windows.xaml
<r:RibbonButton Command="{StaticResource AddNewCommand}" Name="btnSaveItem1" Cursor="Hand" Click="btnSaveItem1_Click"
IsEnabled="True" Opacity="1" BorderThickness="1" />
this button is disabled don't know my

BUT

<r:RibbonButton Name="btnAddNewItem" Cursor="Hand" ></r:RibbonButton>

this is enabled, but i cannot add image and stuff waiting

Thanks
Rahul

Coordinator
Mar 23, 2009 at 5:37 PM
Hi Rahul,

Your RibbonCommand needs a handler for CanExecute which says that the command can execute and therefore enables the button.  Try something like this:

<r:RibbonCommand x:Key="AddNewCommand"
LabelTitle="New Item"
ToolTipTitle="Add New Item"
ToolTipDescription="Add New Stores Item"
SmallImageSource="RibbonImages/AddNew.png"
LargeImageSource="RibbonImages/AddNew.png"
ToolTipImageSource="RibbonImages/AddNew.png"
CanExecute="RibbonCommand_CanExecute"/>
</r:Ribbon.Resources>

In Window1.xaml.cs:

private void RibbonCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = true;
}

Thanks,
Samantha

Mar 24, 2009 at 9:21 AM
Thanks a lot Samantha.
Oct 20, 2009 at 11:57 AM

<r:RibbonWindow.Resources>
        <ResourceDictionary>

            <r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdPrint" LabelTitle="Print" LabelDescription="Print" ToolTipTitle="Help" ToolTipDescription="This is used to Print" SmallImageSource="Images\printIcon.png" LargeImageSource="Images\printIcon.png" />
            <r:RibbonCommand Executed="RibbonCommand_Executed_Exit" x:Key="cmdExit" LabelTitle="Close" LabelDescription="Close" ToolTipTitle="Help" ToolTipDescription="Close Application" SmallImageSource="Images\exitIcon.png" LargeImageSource="Images\exitIcon.png" />
            <r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdHelp" LabelTitle="About" LabelDescription="Help" ToolTipTitle="Help" ToolTipDescription="About Application" SmallImageSource="Images\vdiWorksIcon.png" LargeImageSource="Images\vdiWorksIcon.png" />
            <r:RibbonCommand x:Key="testCmd" Executed="RibbonCommand_Executed" LabelTitle="Test Command" ToolTipDescription="test command" SmallImageSource="Images\vdiWorksIcon.png" LargeImageSource="Images\vdiWorksIcon.png"/>
            
            <!--Theme-->
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>
    </r:RibbonWindow.Resources>

this is 100% percent working code actually i was having same problem and i was using CanExecute but this does not solve my problem so i used Executed and yup my problem is solved now hurray...!!!

Feb 19, 2010 at 3:46 PM
SamanthaMSFT wrote:

Hey guys,

You're seeing this issue because

<CommandBinding Command="me:AppCommands.AddNew" Executed="OnAddNewEntry" />

refers to the following code:

public static RibbonCommand AddNew
{
     get { return (RibbonCommand)Application.Current.Resources["AddNewCommand"]; }
}

 

and at design time, Application.Current doesn’t refer to the runtime application but to the designtime application. This is a limitation of the VS designer and I believe it also applies to Blend.  We'll fix this in an upcoming iteration of the lab by moving all of the RibbonCommands from AppCommands.xaml into the resources of the window in MainWindow.xaml and updating the Ribbon controls to look for those commands.  For now, the workarounds you found should work fine.

Thanks for reporting this issue!
Samantha

Sorry for catching up late on this. I was facing the same issue and the only resolution i found was to move the CommandDeclarations that required a CanExecute and Execute eventhandlers, from AppCommands.xaml to MainWindow.xaml.

My question is:

Is there any better way of doing this?

Thanks