小编NiG*_*hMa的帖子

单选按钮和图像

我尝试为我的 RadioButton 设置图像而不是项目符号。我有 10 个单选按钮,但我无法设置所有的 FishImg。只有我之前单击的 rb 显示 imgFish。

我的风格

    <Style TargetType="RadioButton">
    <Setter Property="Content" Value="{DynamicResource imgFish}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type RadioButton}">
                <Grid>
                    <Image Source="Images/empty.png" Width="24" Height="24" />
                    <ContentPresenter/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsChecked" Value="True">
            <Setter Property="Content" Value="{DynamicResource imgHero}"/>
        </Trigger>
        <Trigger Property="IsChecked" Value="False">
            <Setter Property="Content" Value="{DynamicResource imgFish}"/>
        </Trigger>
    </Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)

我的 XAML

                <RadioButton Grid.Column="2" Grid.Row="1" Name="hvP1" />
                <RadioButton Grid.Column="2" Grid.Row="2" Name="hvP2" />
                <RadioButton Grid.Column="2" Grid.Row="3" Name="hvP3" />
                <RadioButton Grid.Column="2" Grid.Row="4" Name="hvP4" />
                <RadioButton Grid.Column="2" Grid.Row="5" Name="hvP5" />
                <RadioButton …
Run Code Online (Sandbox Code Playgroud)

c# xaml toggle radio-button

2
推荐指数
1
解决办法
7341
查看次数

标签 统计

c# ×1

radio-button ×1

toggle ×1

xaml ×1