gpt4 book ai didi

c# - WPF 功能区 : DataTemplate causes BindingExpression path error

转载 作者:太空狗 更新时间:2023-10-29 23:26:41 25 4
gpt4 key购买 nike

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

System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“RibbonContentPresenter”(名称=“PART_ContentPresenter”)上找不到“IsDropDownOpen”属性。绑定(bind)表达式:Path=IsDropDownOpen; DataItem='RibbonContentPresenter' (Name='PART_ContentPresenter');目标元素是 'RibbonButton' (Name='');目标属性是“NoTarget”(类型“Object”)

这是一个代码片段,viewmodel被一个字符串数组代替,但是问题是一样的:

<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>

再次,它有效,但绑定(bind)错误有点烦人。有什么办法可以摆脱它?

最佳答案

绑定(bind)错误出现在 RibbonControlsLibrary 中 RibbonButton 的控件模板中。该样式定义了以下 MultiDataTrigger,并在 RibbonButton 用作另一个控件的一部分时使用,例如 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>

关于c# - WPF 功能区 : DataTemplate causes BindingExpression path error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4276010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com