WPF丝带:DataTemplate中引起BindingExpression路径错误 [英] WPF Ribbon: DataTemplate causes BindingExpression path error

查看:1006
本文介绍了WPF丝带:DataTemplate中引起BindingExpression路径错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到使用WPF RibbonControl(2010年10月版)的一个小问题。我的想法是一个RibbonGroup的ItemsSource属性绑定到我的视图模型,并使用一个DataTemplate根据需要创建RibbonButtons。这工作,但它会导致一个绑定错误(每个按钮),当您显示窗口:

I've run into a small problem using the WPF RibbonControl (October 2010 version). My idea was to bind the ItemsSource property of a RibbonGroup to my viewmodel, and use a DataTemplate to create RibbonButtons as needed. This works, but it causes a binding error (one for each button) when you show the window:

System.Windows.Data错误:40 :BindingExpression路径错误:'IsDropDownOpen'属性不是'对象'''RibbonContentPresenter'(名称='PART_ContentPresenter')'找到。 BindingExpression:路径= IsDropDownOpen;的DataItem ='RibbonContentPresenter'(名称='PART_ContentPresenter');目标元素是'RibbonButton'(名称=''); target属性是'NoTarget'(类型'对象')

下面是一个代码片段,该视图模型是由一个字符串数组取代,但问题是相同的:

Here is a code fragment, the viewmodel is replaced by an array of strings, but the issue is the same:

<ribbon:RibbonWindow x:Class="WpfRibbonApplication1.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"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" x:Name="RibbonWindow" Width="640" Height="480" >

    <ribbon:RibbonWindow.Resources>
        <x:Array x:Key="buttonArray" Type="sys:String">
            <sys:String>Button 1</sys:String>
            <sys:String>Button 2</sys:String>
            <sys:String>Button 3</sys:String>
            <sys:String>Button 4</sys:String>
            <sys:String>Button 5</sys:String>
            <sys:String>Button 6</sys:String>
        </x:Array>
        <DataTemplate x:Key="buttonTemplate">
            <ribbon:RibbonButton Label="{Binding}"  />
        </DataTemplate>        
    </ribbon:RibbonWindow.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ribbon:Ribbon>
            <ribbon:RibbonTab Header="Tab1">
                <ribbon:RibbonGroup Header="Group1"
                    ItemsSource="{StaticResource buttonArray}" 
                    ItemTemplate="{StaticResource buttonTemplate}"
                />
            </ribbon:RibbonTab>
        </ribbon:Ribbon>         
    </Grid>
</ribbon:RibbonWindow>

再次,它的工作原理,但绑定错误是有点讨厌。有什么办法来摆脱它?

Again, it works, but the binding error is a bit annoying. Is there any way to get rid of it?

推荐答案

绑定错误是在为RibbonControlsLibrary内RibbonButton控件模板。样式有以下MultiDataTrigger定义,当RibbonButton用作另一控制的一部分,就像RibbonSplitButton被使用。

The binding error is in the control template for the RibbonButton within the RibbonControlsLibrary. The style has the following MultiDataTrigger defined and is used when the RibbonButton is used as part of another control, like the RibbonSplitButton.

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen}" Value="True" />
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="False" />
        <Condition Binding="{Binding Path=HighContrast, Source={x:Static shell:SystemParameters2.Current}}" Value="True" />
    </MultiDataTrigger.Conditions>
    <Setter TargetName="OuterBorder" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" />
</MultiDataTrigger>

这篇关于WPF丝带:DataTemplate中引起BindingExpression路径错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆