3

我正在使用 Microsoft.Windows.Controls.Ribbon。

我想在我的功能区中有一个带有图片按钮的动态组合框。

如果我直接在 xaml 中执行此操作,我会得到我想要的:

<ribbon:RibbonComboBox 
                      SelectionBoxWidth="62"
                      VerticalAlignment="Center" 
                      >
                    <ribbon:RibbonGallery SelectedValue="0"
                      SelectedValuePath="Content"
                      MaxColumnCount="1">
                        <ribbon:RibbonGalleryCategory>
                            <ribbon:RibbonButton Label="Histo"  HorizontalContentAlignment="Stretch"
                                       Command="{Binding NewHistogrammCommand}" 
                                       SmallImageSource="/Test;component/Resourcen/Histogramm32.png" 
                                       LargeImageSource="/Test;component/Resourcen/Histogramm32.png" />
                            <ribbon:RibbonButton Label="3D"  HorizontalContentAlignment="Stretch"
                                       Command="{Binding NewDreiDCommand}" 
                                       SmallImageSource="/Test;component/Resourcen/DreiD32.png" 
                                       LargeImageSource="/Test;component/Resourcen/DreiD32.png" />
                        </ribbon:RibbonGalleryCategory>
                    </ribbon:RibbonGallery>
                </ribbon:RibbonComboBox>

但是,如果我尝试通过这种方式绑定到集合来做到这一点:

                    <ribbon:RibbonComboBox 
                      SelectionBoxWidth="62"
                      VerticalAlignment="Center" 
                      IsEditable="True" >
                    <ribbon:RibbonGallery
                      MaxColumnCount="1">
                        <ribbon:RibbonGalleryCategory ItemsSource="{Binding LayoutContentTypeList, ElementName=mainWindow}">
                            <ribbon:RibbonGalleryCategory.ItemTemplate>
                                <DataTemplate>
                                    <ribbon:RibbonButton Label="{Binding Header}" HorizontalContentAlignment="Stretch"
                                           Command="{Binding Command}" 
                                           CommandParameter="{Binding CommandParameter}" 
                                           SmallImageSource="{Binding ImageSource}"
                                           LargeImageSource="{Binding ImageSource}" />
                                </DataTemplate>
                            </ribbon:RibbonGalleryCategory.ItemTemplate>
                        </ribbon:RibbonGalleryCategory>
                    </ribbon:RibbonGallery>
                </ribbon:RibbonComboBox>

我明白了

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

按钮可以正常工作,但如何解决此绑定错误?

4

1 回答 1

3

我猜您已经找到了解决问题的方法,但是对于遇到此帖子的其他人,在寻找答案时,您可以找到一个完整的解决方案,您可以在我如何添加中下载并在闲暇时检查画廊到我的功能区?在“Windows Presentation Foundation 团队的官方博客”上发帖。基本思路如下。

无论您设置为什么对象,都RibbonGallery.DataContext应该有一个集合属性来绑定到该RibbonGalleryCategory.ItemsSource属性。该集合中的对象应具有包含您希望在图库项目中显示的值的属性。声明一个HierarchicalDataTemplateRibbonGallery.CategoryTemplate绑定你的属性。这是链接帖子中的一个示例:

<Ribbon:RibbonGallery DataContext="{x:Static data:WordModel.StylesParagraphGalleryData}" 
ItemsSource="{Binding CategoryDataCollection}" 
ScrollViewer.VerticalScrollBarVisibility="Hidden">
    <Ribbon:RibbonGallery.CategoryTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding GalleryItemDataCollection}">
            <Border Background="LightGray">
                <TextBlock Text="{Binding}" FontWeight="Bold" />
            </Border>
            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Images\Paragraph_32x32.png" />
                        <TextBlock Margin="10,0,0,0" Text="{Binding}" />
                    </StackPanel>
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>
    </Ribbon:RibbonGallery.CategoryTemplate>
</Ribbon:RibbonGallery>
于 2013-08-18T15:28:50.707 回答