C# 有没有办法显示星星的图像而不是单选按钮
在WPF中C# 有没有办法显示星星的图像而不是单选按钮,c#,.net,wpf,C#,.net,Wpf,在WPF中 抱歉,这是一个基本问题,还在这里学习基本知识 是的,你可以。问题是您必须为radiobutton创建xaml样式,您可以替换控件模板 复制/粘贴/运行此愚蠢的示例: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/w
抱歉,这是一个基本问题,还在这里学习基本知识 是的,你可以。问题是您必须为radiobutton创建xaml样式,您可以替换控件模板
复制/粘贴/运行此愚蠢的示例:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type RadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<StackPanel Orientation="Horizontal">
<Polygon x:Name="star" Fill="Transparent" Stroke="Gray" StrokeThickness="2" Points="18,4 22,14 35,14 24,20 28,30 18,24 8,30 12,20 2,14 14,14"/>
<TextBlock Text="{TemplateBinding Content}" VerticalAlignment="Center" Margin="4,0"/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="RadioButton.IsChecked" Value="True">
<Setter TargetName="star" Property="Polygon.Fill" Value="Gold"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<RadioButton Content="one" GroupName="sillySample" IsChecked="True" />
<RadioButton Content="two" GroupName="sillySample"/>
<RadioButton Content="tree" GroupName="sillySample"/>
</StackPanel>
简言之,在WPF中,您可以覆盖某些控件模板,以将内部控件结构与您想要的任何内容交换,同时保持其行为,正如我在这里所做的(只是为了演示这一点),我使用RadioButton.IsChecked属性将填充设置为Gold,因为它(IsChecked)不属于textblock或polygon,然而,我仍然能够使用它,因为我覆盖了RadioButton的模板
不管怎样,祝你好运
丹尼斯任何样品都会非常有用