【问题标题】:WPF How to set style on RadioButton?WPF 如何在 RadioButton 上设置样式?
【发布时间】:2014-09-23 19:18:52
【问题描述】:

我有这个代码:

                 <GroupBox Grid.Column="1" BorderThickness="0,0,0,0" HorizontalAlignment="Right">
                    <ItemsControl FontWeight="Normal" 
                                  ItemsSource="{Binding Path=AvailableTipologieDifficolta}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <RadioButton
                                  Content="{Binding Path=DisplayName}"
                                  IsChecked="{Binding Path=IsSelected}"
                                  GroupName="Feedback"
                                  Margin="10,3.5"
                                  Style="{StaticResource RadioButtonTemplate}"
                                />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </GroupBox>

这是 RadioButton 的样式:

        <Style TargetType="RadioButton" x:Key="RadioButtonTemplate">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <RadioButton Foreground="White" FontSize="20">
                            <ContentPresenter/>
                        </RadioButton>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

所以当我尝试运行我的代码时,我有这个:

o 选项 1 o Opzione 2

我可以选择每个选项,但这是不可能的。如果我删除此代码 Style="{StaticResource RadioButtonTemplate}" 我可以选择一个选项。

我们能帮帮我吗?

【问题讨论】:

  • 我们能帮帮我吗?...用文字来解释你的问题和你想要的结果。

标签: c# wpf radio-button


【解决方案1】:

这是因为您在创建这样的模板时将RadioButton 包装在RadioButton 中。内部RadioButton 未链接到外部RadioButton。您不需要为您想要做的事情更改模板,只需使用 2 SettersForegroundFontSize

<Style TargetType="RadioButton" x:Key="RadioButtonTemplate">
    <Setter Property="Foreground" Value="White"/>
    <Setter Property="FontSize" Value="20"/>
</Style>

【讨论】:

  • 谢谢你,我解决了我的问题
猜你喜欢
  • 1970-01-01
  • 2013-08-25
  • 1970-01-01
  • 1970-01-01
  • 2013-11-26
  • 2014-11-11
  • 1970-01-01
  • 1970-01-01
  • 2017-11-29
相关资源
最近更新 更多