Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有没有办法显示星星的图像而不是单选按钮_C#_.net_Wpf - Fatal编程技术网

C# 有没有办法显示星星的图像而不是单选按钮

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

在WPF中


抱歉,这是一个基本问题,还在这里学习基本知识

是的,你可以。问题是您必须为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的模板

不管怎样,祝你好运


丹尼斯

任何样品都会非常有用