我遇到了一个小问题,使用WPF RibbonControl(2010年10月版)。我的想法是将RibbonGroup的ItemsSource属性绑定到我的视图模型,并根据需要使用DataTemplate创建RibbonButton。这工作,但它会导致一个绑定错误(每个按钮),当您显示窗口:WPF功能区:DataTemplate导致BindingExpression路径错误
System.Windows.Data Error: 40 : BindingExpression path error: 'IsDropDownOpen' property not found on 'object' ''RibbonContentPresenter' (Name='PART_ContentPresenter')'. BindingExpression:Path=IsDropDownOpen; DataItem='RibbonContentPresenter' (Name='PART_ContentPresenter'); target element is 'RibbonButton' (Name=''); target property is 'NoTarget' (type 'Object')
下面是一个代码片段,该视图模型是由字符串数组替代,但问题是相同:
<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>
再一次,它的工作原理,但绑定错误是有点烦人。有什么办法摆脱它吗?
为功能区按钮创建一个自定义控制模板的窍门。 – janemann 2010-12-05 12:39:33