在一个WPF应用程序中,使用Fluent Ribbon Control Suite,我有一个DropDownButton,它打开一个画廊,让用户选择颜色。
选项卡库的SelectedItem返回颜色名称。我想让按钮的图标显示所选的实际颜色。这可以纯粹通过XAML完成吗?我已经尝试了一些在网上找到的方法,但迄今为止,除了颜色名称出现在我想要的颜色矩形位置之外,我无法得到其他任何东西。请查看上面XAML中的“这里是什么?”。
感谢任何有用的建议。谢谢阅读!
更新:
我尝试了下面给出的答案,但仍然不起作用。我一定做错了什么。这是此按钮所有XAML代码的更新列表。查看选项卡库本身的XAML和SolidColorBrush的绑定,并告诉我您是否看到了我的错误。
这是创建按钮的XAML代码:
<Fluent:DropDownButton x:Name="btnCommentColor" Header="Comments">
<Fluent:DropDownButton.Icon>
<!-- What goes here? -->
</Fluent:DropDownButton.Icon>
<Fluent:Gallery x:Name="galCommentColor" ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}" SelectedValuePath="Name" MaxItemsInRow="12">
<Fluent:Gallery.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" CornerRadius="2" BorderBrush="Black" Width="25" Height="25" VerticalAlignment="Stretch" Background="{Binding Name}" />
</DataTemplate>
</Fluent:Gallery.ItemTemplate>
</Fluent:Gallery>
</Fluent:DropDownButton>
选项卡库的SelectedItem返回颜色名称。我想让按钮的图标显示所选的实际颜色。这可以纯粹通过XAML完成吗?我已经尝试了一些在网上找到的方法,但迄今为止,除了颜色名称出现在我想要的颜色矩形位置之外,我无法得到其他任何东西。请查看上面XAML中的“这里是什么?”。
感谢任何有用的建议。谢谢阅读!
更新:
我尝试了下面给出的答案,但仍然不起作用。我一定做错了什么。这是此按钮所有XAML代码的更新列表。查看选项卡库本身的XAML和SolidColorBrush的绑定,并告诉我您是否看到了我的错误。
<Window.Resources>
<ObjectDataProvider MethodName="GetType"
ObjectType="{x:Type sys:Type}" x:Key="colorsTypeOdp">
<ObjectDataProvider.MethodParameters>
<sys:String>System.Windows.Media.Colors, PresentationCore,
Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider ObjectInstance="{StaticResource colorsTypeOdp}"
MethodName="GetProperties" x:Key="colorPropertiesOdp">
</ObjectDataProvider>
</Window.Resources>
<Fluent:DropDownButton Name="btnCommentColor" Header="Comments">
<Fluent:DropDownButton.LargeIcon>
<Grid Width="32" Height="32">
<Image Source="Icons\BlueLarge.png" />
<Border Height="32" VerticalAlignment="Bottom" BorderThickness="0" CornerRadius="2">
<Border.Background>
<SolidColorBrush Color="{Binding ElementName=galCommentColor, Path=SelectedValue, FallbackValue=Green}" />
</Border.Background>
</Border>
</Grid>
</Fluent:DropDownButton.LargeIcon>
<Fluent:Gallery Name="galCommentColor" ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}" SelectedValuePath="Name" MaxItemsInRow="12">
<Fluent:Gallery.ItemTemplate>
<DataTemplate>
<Border ToolTip="{Binding Path=Name}" BorderThickness="1" CornerRadius="2" BorderBrush="Black" Width="25" Height="25" VerticalAlignment="Stretch" Background="{Binding Name}" />
</DataTemplate>
</Fluent:Gallery.ItemTemplate>
</Fluent:Gallery>
</Fluent:DropDownButton>