6

I want to build a RibbonApplicationMenu. Within it shall be a nested RibbonApplicationMenuItem or RibbonApplicationSplitMenuItem, e.g. likes this:

<ribbon:RibbonApplicationSplitMenuItem x:Name="item1" Header="open project" ImageSource="../img/img1.png">
       <ribbon:RibbonApplicationMenuItem x:Name="item11" Header="sub1" ImageSource="../img/img2.png" />
       <ribbon:RibbonApplicationMenuItem x:Name="item12" Header="sub2" ImageSource="../img/img3.png" />
       <ribbon:RibbonApplicationMenuItem x:Name="item13" Header="sub3" ImageSource="../img/img3.png" />
</ribbon:RibbonApplicationSplitMenuItem>

At first there is no error shown and the program can be built successfully.

When I continue work the entire section is labeled and an error is given:

The index '0' is out of the valid range of the PathParameters-List with the length '0'

What is the reason for this error?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • 1
    This seems to be a designer-issue only. I agree it might be annoying, but not even google finds anything under this errormessage – lokusking Aug 11 '16 at 15:49
  • 1
    Please, share a **verifiable** example. –  Aug 11 '16 at 17:33
  • Try using two forward slashes instead of one on the image source link `ImageSource="..//img/lifeUp2.jpg" `. It works for me... Let me know if that works for you, if it does I'll try and post an explanation on this post. – JoshuaTheMiller Aug 12 '16 at 20:06
  • Possible duplicate of [What does Binding="{Binding (0)}" mean?](https://stackoverflow.com/questions/21879168/what-does-binding-binding-0-mean) – StayOnTarget Apr 25 '19 at 11:32

1 Answers1

8

This is very easy to understand and to fix, but there is no real need to do that.

The Reason

The issue is that in the standard ribbon templates there are many wrong placeholders

<Condition Binding="{Binding  (0)}" Value="True"/>

The Fix

Long story short, you need to change the above into, for example:

<Condition Binding="{Binding  Zero }" Value="True"/>

How to do that?

That's not trivial, but you can do it with a little of attention..

You have to add a reference to PresentationFramework.Classic

Then, let me start from the end... the objective is defining the following

<Window.Resources>
    <Style TargetType="{x:Type RibbonButton}" >
        <Setter Property="Template" Value="{DynamicResource RibbonButtonControlTemplate1}"/>
    </Style>

    <Style TargetType="{x:Type RibbonApplicationSplitMenuItem}" >
        <Setter Property="Template" Value="{DynamicResource RibbonApplicationSplitMenuItemControlTemplate1}"/>
    </Style>


    <Style TargetType="{x:Type RibbonApplicationMenuItem}" >
        <Setter Property="Template" Value="{DynamicResource RibbonApplicationMenuItemControlTemplate1}"/>
    </Style>

</Window.Resources>

The missing control templates

What is still missing? Three very big pieces of code containing the above ControlTemplates... but there is a trick to include them:

  • move the cursor to (for example) RibbonApplicationMenuItem and locate the Template in the Properties Window

  • click on the right Ambient and select Convert to New Resource...

    In conclusion you will run an overall replace from (0) to Zero through all of your xaml.

Again, this is intended as a pure academic exercise.

Community
  • 1
  • 1
  • Unfortunately I have no time to check this solution before the bounty expires. So I will award the bounty now and probably accept it later. – Dabblernl Aug 18 '16 at 08:14
  • The invalid binding syntax has been reported at: https://developercommunity.visualstudio.com/content/problem/545784/invalid-syntax-inside-ribbon-control-templates-bin.html – StayOnTarget Apr 25 '19 at 11:31
  • I answered a question that documents the process of getting the default `ControlTemplate` in the [How to Extract Default Control Template In Visual Studio?](https://stackoverflow.com/questions/8825030/how-to-extract-default-control-template-in-visual-studio/28212036#28212036) question, here on Stack Overflow. – Sheridan Aug 23 '19 at 08:45
  • Microsoft issue migrated to: https://github.com/dotnet/wpf/issues/647 – StayOnTarget Oct 11 '19 at 16:07