|
| 1 | +<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
| 2 | +<Design.PreviewWith> |
| 3 | + <Border Padding="20"> |
| 4 | + <StackPanel Spacing="10"> |
| 5 | + <RadioButton Content="Option 1" Background="Green" /> |
| 6 | + <RadioButton Content="Option 2" /> |
| 7 | + <RadioButton IsEnabled="False" Content="Option 3" /> |
| 8 | + <RadioButton Content="Option 2" /> |
| 9 | + </StackPanel> |
| 10 | + </Border> |
| 11 | +</Design.PreviewWith> |
| 12 | + |
| 13 | +<Style Selector="RadioButton"> |
| 14 | + <Setter Property="Background" Value="{DynamicResource RadioButtonBackground}" /> |
| 15 | + <Setter Property="Foreground" Value="{DynamicResource RadioButtonForeground}" /> |
| 16 | + <Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrush}" /> |
| 17 | + <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" /> |
| 18 | + <Setter Property="Padding" Value="4,0,0,0" /> |
| 19 | + <Setter Property="HorizontalAlignment" Value="Left" /> |
| 20 | + <Setter Property="VerticalAlignment" Value="Center" /> |
| 21 | + <Setter Property="HorizontalContentAlignment" Value="Left" /> |
| 22 | + <Setter Property="VerticalContentAlignment" Value="Center" /> |
| 23 | + <Setter Property="Template"> |
| 24 | + <ControlTemplate TargetType="RadioButton"> |
| 25 | + <Border |
| 26 | + Name="RootBorder" |
| 27 | + Background="{TemplateBinding Background}" |
| 28 | + BorderBrush="{TemplateBinding BorderBrush}" |
| 29 | + BorderThickness="{TemplateBinding BorderThickness}" |
| 30 | + CornerRadius="{TemplateBinding CornerRadius}"> |
| 31 | + <Grid ColumnDefinitions="14,*"> |
| 32 | + <Grid Height="18" VerticalAlignment="Top"> |
| 33 | + |
| 34 | + <Ellipse |
| 35 | + Name="OuterEllipse" |
| 36 | + Width="14" |
| 37 | + Height="14" |
| 38 | + Fill="{DynamicResource RadioButtonOuterEllipseFill}" |
| 39 | + Stroke="{DynamicResource RadioButtonOuterEllipseStroke}" |
| 40 | + StrokeThickness="{DynamicResource RadioButtonBorderThemeThickness}" |
| 41 | + UseLayoutRounding="False" /> |
| 42 | + |
| 43 | + <Ellipse |
| 44 | + Name="CheckOuterEllipse" |
| 45 | + Width="14" |
| 46 | + Height="14" |
| 47 | + Fill="{DynamicResource RadioButtonOuterEllipseCheckedFill}" |
| 48 | + Opacity="0" |
| 49 | + Stroke="{DynamicResource RadioButtonOuterEllipseCheckedStroke}" |
| 50 | + StrokeThickness="{DynamicResource RadioButtonBorderThemeThickness}" |
| 51 | + UseLayoutRounding="False" /> |
| 52 | + |
| 53 | + <Ellipse |
| 54 | + Name="CheckGlyph" |
| 55 | + Width="6" |
| 56 | + Height="6" |
| 57 | + Fill="{DynamicResource RadioButtonCheckGlyphFill}" |
| 58 | + Opacity="0" |
| 59 | + Stroke="{DynamicResource RadioButtonCheckGlyphStroke}" |
| 60 | + UseLayoutRounding="False" /> |
| 61 | + </Grid> |
| 62 | + |
| 63 | + <ContentPresenter |
| 64 | + Name="PART_ContentPresenter" |
| 65 | + Grid.Column="1" |
| 66 | + Margin="{TemplateBinding Padding}" |
| 67 | + HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" |
| 68 | + VerticalAlignment="{TemplateBinding VerticalContentAlignment}" |
| 69 | + Content="{TemplateBinding Content}" |
| 70 | + ContentTemplate="{TemplateBinding ContentTemplate}" |
| 71 | + Foreground="{TemplateBinding Foreground}" /> |
| 72 | + </Grid> |
| 73 | + </Border> |
| 74 | + </ControlTemplate> |
| 75 | + </Setter> |
| 76 | +</Style> |
| 77 | + |
| 78 | +<Style Selector="RadioButton /template/ ContentPresenter#PART_ContentPresenter"> |
| 79 | + <Setter Property="RecognizesAccessKey" Value="True" /> |
| 80 | + </Style> |
| 81 | + |
| 82 | + <!-- PointerOver State --> |
| 83 | + <Style Selector="RadioButton:pointerover /template/ ContentPresenter#PART_ContentPresenter"> |
| 84 | + <Setter Property="Foreground" Value="{DynamicResource RadioButtonForegroundPointerOver}" /> |
| 85 | + </Style> |
| 86 | + |
| 87 | + <Style Selector="RadioButton:pointerover /template/ Border#RootBorder"> |
| 88 | + <Setter Property="Background" Value="{DynamicResource RadioButtonBackgroundPointerOver}" /> |
| 89 | + <Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrushPointerOver}" /> |
| 90 | + </Style> |
| 91 | + |
| 92 | + <Style Selector="RadioButton:pointerover /template/ Ellipse#OuterEllipse"> |
| 93 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseStrokePointerOver}" /> |
| 94 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseFillPointerOver}" /> |
| 95 | + </Style> |
| 96 | + |
| 97 | + <Style Selector="RadioButton:pointerover /template/ Ellipse#CheckOuterEllipse"> |
| 98 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseCheckedStrokePointerOver}" /> |
| 99 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseCheckedFillPointerOver}" /> |
| 100 | + </Style> |
| 101 | + |
| 102 | + <Style Selector="RadioButton:pointerover /template/ Ellipse#CheckGlyph"> |
| 103 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckGlyphStrokePointerOver}" /> |
| 104 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonCheckGlyphFillPointerOver}" /> |
| 105 | + </Style> |
| 106 | + |
| 107 | + |
| 108 | + <!-- Pressed State --> |
| 109 | + <Style Selector="RadioButton:pressed /template/ ContentPresenter#PART_ContentPresenter"> |
| 110 | + <Setter Property="Foreground" Value="{DynamicResource RadioButtonForegroundPressed}" /> |
| 111 | + </Style> |
| 112 | + |
| 113 | + <Style Selector="RadioButton:pressed /template/ Border#RootBorder"> |
| 114 | + <Setter Property="Background" Value="{DynamicResource RadioButtonBackgroundPressed}" /> |
| 115 | + <Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrushPressed}" /> |
| 116 | + </Style> |
| 117 | + |
| 118 | + <Style Selector="RadioButton:pressed /template/ Ellipse#OuterEllipse"> |
| 119 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseStrokePressed}" /> |
| 120 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseFillPressed}" /> |
| 121 | + </Style> |
| 122 | + |
| 123 | + <Style Selector="RadioButton:pressed /template/ Ellipse#CheckOuterEllipse"> |
| 124 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseCheckedStrokePressed}" /> |
| 125 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseCheckedFillPressed}" /> |
| 126 | + </Style> |
| 127 | + |
| 128 | + <Style Selector="RadioButton:pressed /template/ Ellipse#CheckGlyph"> |
| 129 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckGlyphStrokePressed}" /> |
| 130 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonCheckGlyphFillPressed}" /> |
| 131 | + </Style> |
| 132 | + |
| 133 | + |
| 134 | + <!-- Disabled State --> |
| 135 | + <Style Selector="RadioButton:disabled /template/ ContentPresenter#PART_ContentPresenter"> |
| 136 | + <Setter Property="Foreground" Value="{DynamicResource RadioButtonForegroundDisabled}" /> |
| 137 | + </Style> |
| 138 | + |
| 139 | + <Style Selector="RadioButton:disabled /template/ Border#RootBorder"> |
| 140 | + <Setter Property="Background" Value="{DynamicResource RadioButtonBackgroundDisabled}" /> |
| 141 | + <Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrushDisabled}" /> |
| 142 | + </Style> |
| 143 | + |
| 144 | + <Style Selector="RadioButton:disabled /template/ Ellipse#OuterEllipse"> |
| 145 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseStrokeDisabled}" /> |
| 146 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseFillDisabled}" /> |
| 147 | + </Style> |
| 148 | + |
| 149 | + <Style Selector="RadioButton:disabled /template/ Ellipse#CheckOuterEllipse"> |
| 150 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseCheckedStrokeDisabled}" /> |
| 151 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseCheckedFillDisabled}" /> |
| 152 | + </Style> |
| 153 | + |
| 154 | + <Style Selector="RadioButton:disabled /template/ Ellipse#CheckGlyph"> |
| 155 | + <Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckGlyphFillDisabled}" /> |
| 156 | + <Setter Property="Fill" Value="{DynamicResource RadioButtonCheckGlyphStrokeDisabled}" /> |
| 157 | + </Style> |
| 158 | + |
| 159 | + |
| 160 | + <!-- Checked State --> |
| 161 | + <Style Selector="RadioButton:checked /template/ Ellipse#CheckGlyph"> |
| 162 | + <Setter Property="Opacity" Value="1" /> |
| 163 | + </Style> |
| 164 | + |
| 165 | + <Style Selector="RadioButton:checked /template/ Ellipse#OuterEllipse"> |
| 166 | + <Setter Property="Opacity" Value="0" /> |
| 167 | + </Style> |
| 168 | + |
| 169 | + <Style Selector="RadioButton:checked /template/ Ellipse#CheckOuterEllipse"> |
| 170 | + <Setter Property="Opacity" Value="1" /> |
| 171 | + </Style> |
| 172 | +</Styles> |
0 commit comments