Xaml UWP应用程序创建不带选定圆圈的单选按钮

Xaml UWP应用程序创建不带选定圆圈的单选按钮,xaml,radio-button,uwp,Xaml,Radio Button,Uwp,在通用Windows平台上,如何创建外观类似按钮的RadioButton?所选按钮将显示为按下,而不是选中的圆圈 谢谢 你必须使用单选按钮的风格。因此,您可以使用VisualStates和OuterEllipse,CheckOuterEllipse和CheckGlyph省略号,并删除/更改所需内容 <Style TargetType="RadioButton"> <Setter Property="Background" Value="Transparent" />

在通用Windows平台上,如何创建外观类似按钮的RadioButton?所选按钮将显示为按下,而不是选中的圆圈


谢谢

你必须使用
单选按钮的
风格
。因此,您可以使用
VisualStates
OuterEllipse
CheckOuterEllipse
CheckGlyph
省略号,并删除/更改所需内容

<Style TargetType="RadioButton">
  <Setter Property="Background" Value="Transparent" />
  <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/>
  <Setter Property="Padding" Value="8,6,0,0" />
  <Setter Property="HorizontalAlignment" Value="Left" />
  <Setter Property="VerticalAlignment" Value="Center" />
  <Setter Property="HorizontalContentAlignment" Value="Left" />
  <Setter Property="VerticalContentAlignment" Value="Top" />
  <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
  <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
  <Setter Property="MinWidth" Value="120" />
  <Setter Property="UseSystemFocusVisuals" Value="True" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="RadioButton">
        <Grid Background="{TemplateBinding Background}"
              BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}">
        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal" />
            <VisualState x:Name="PointerOver">
              <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="OuterEllipse"
                                               Storyboard.TargetProperty="Stroke">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseHighBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckOuterEllipse"
                                               Storyboard.TargetProperty="Stroke">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckOuterEllipse"
                                               Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph"
                                               Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                </ObjectAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="Pressed">
              <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="OuterEllipse"
                                               Storyboard.TargetProperty="Stroke">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckOuterEllipse"
                                                Storyboard.TargetProperty="Stroke">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckOuterEllipse"
                                                Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph"
                                               Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumBrush}" />
                </ObjectAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="Disabled">
              <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="OuterEllipse"
                                               Storyboard.TargetProperty="Stroke">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckOuterEllipse"
                                                Storyboard.TargetProperty="Stroke">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckOuterEllipse"
                                                Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph"
                                               Storyboard.TargetProperty="Fill">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
                </ObjectAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
          </VisualStateGroup>
          <VisualStateGroup x:Name="CheckStates">
            <VisualState x:Name="Checked">
              <Storyboard>
                <DoubleAnimation Storyboard.TargetName="CheckGlyph"
                                 Storyboard.TargetProperty="Opacity"
                                 To="1"
                                 Duration="0" />
                <DoubleAnimation Storyboard.TargetName="OuterEllipse"
                                 Storyboard.TargetProperty="Opacity"
                                 To="0"
                                 Duration="0" />
                <DoubleAnimation Storyboard.TargetName="CheckOuterEllipse"
                                 Storyboard.TargetProperty="Opacity"
                                 To="1"
                                 Duration="0" />
              </Storyboard>
            </VisualState>
            <VisualState x:Name="Unchecked" />
            <VisualState x:Name="Indeterminate" />
          </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20" />
            <ColumnDefinition Width="*" />
          </Grid.ColumnDefinitions>
          <Grid VerticalAlignment="Top" Height="32" >
            <Ellipse x:Name="OuterEllipse"
                      Width="20"
                      Height="20"
                      UseLayoutRounding="False"
                      Stroke="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                      StrokeThickness="{ThemeResource RadioButtonBorderThemeThickness}" />
            <Ellipse x:Name="CheckOuterEllipse"
                      Width="20"
                      Height="20"
                      UseLayoutRounding="False"
                      Stroke="{ThemeResource SystemControlHighlightAltAccentBrush}"
                      Fill="{ThemeResource SystemControlHighlightTransparentBrush}"
                      Opacity="0"
                      StrokeThickness="{ThemeResource RadioButtonBorderThemeThickness}" />
            <Ellipse x:Name="CheckGlyph"
                      Width="10"
                      Height="10"
                      UseLayoutRounding="False"
                      Opacity="0"
                      Fill="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
          </Grid>
          <ContentPresenter x:Name="ContentPresenter"
                            Content="{TemplateBinding Content}"
                            ContentTransitions="{TemplateBinding ContentTransitions}"
                            ContentTemplate="{TemplateBinding ContentTemplate}"
                            Margin="{TemplateBinding Padding}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Grid.Column="1"
                            AutomationProperties.AccessibilityView="Raw"
                            TextWrapping="Wrap" />
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>