mountaineer
mountaineer

Reputation: 71

Error in nested RibbonApplicationMenuItem

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?

Upvotes: 6

Views: 1074

Answers (1)

user6730148
user6730148

Reputation:

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.

Upvotes: 8

Related Questions