Error in nested RibbonApplicationMenuItem

萝らか妹 提交于 2019-12-07 03:07:54

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/36350664/error-in-nested-ribbonapplicationmenuitem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!