Wpf 内椭圆不在中心位置

Wpf 内椭圆不在中心位置,wpf,xaml,radio-button,Wpf,Xaml,Radio Button,我需要用动画定制RadioButton,我修改了一个动画的内椭圆。但是内椭圆没有加载到中心位置,对此有什么解决方案吗 我已经使用了这个样式,下面给出了示例代码。我刚刚对内部椭圆使用了DoubleAnimation <Style x:Key="RadioButtonStyle" TargetType="RadioButton"> <Setter Property="Background" Value="White"/> <

我需要用动画定制RadioButton,我修改了一个动画的内椭圆。但是内椭圆没有加载到中心位置,对此有什么解决方案吗

我已经使用了这个样式,下面给出了示例代码。我刚刚对内部椭圆使用了DoubleAnimation

        <Style x:Key="RadioButtonStyle" TargetType="RadioButton">
        <Setter Property="Background" Value="White"/>
        <Setter Property="BorderBrush" Value="LightGray"/>
        <Setter Property="Foreground" Value="#333333"/>
        <Setter Property="FontSize" Value="12"/>
        <Setter Property="FontFamily" Value="Segoe UI"/>
        <Setter Property="Padding" Value="10 0"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Cursor" Value="Hand"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RadioButton">
                    <Grid x:Name="Root" Background="Transparent">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation To="0.3" Duration="0" Storyboard.TargetName="Content" Storyboard.TargetProperty="(UIElement.Opacity)"/>
                                        <DoubleAnimation To="0.6" Duration="0" Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.Opacity)"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="CheckStates">
                                <VisualState x:Name="Unchecked">
                                    <Storyboard>
                                        <DoubleAnimation From="8" To="0" Duration="0:0:0.2" Storyboard.TargetName="CheckVisual" Storyboard.TargetProperty="(FrameworkElement.Width)"/>
                                        <DoubleAnimation From="8" To="0" Duration="0:0:0.2" Storyboard.TargetName="CheckVisual" Storyboard.TargetProperty="(FrameworkElement.Height)"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Checked">
                                    <Storyboard>
                                        <DoubleAnimation From="0" To="8" Duration="0:0:0.2" Storyboard.TargetName="CheckVisual" Storyboard.TargetProperty="(FrameworkElement.Width)"/>
                                        <DoubleAnimation From="0" To="8" Duration="0:0:0.2" Storyboard.TargetName="CheckVisual" Storyboard.TargetProperty="(FrameworkElement.Height)"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Indeterminate">
                                    <Storyboard>
                                        <DoubleAnimation From="0" To="1" Duration="0" Storyboard.TargetName="IndeterminateVisual" Storyboard.TargetProperty="(UIElement.Opacity)"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Unfocused"/>
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation From="0" To="1" Duration="0" Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="(UIElement.Opacity)"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid x:Name="grid" Margin="1" Width="13" Height="13" VerticalAlignment="Center" Background="Transparent" HorizontalAlignment="Left">
                            <Ellipse x:Name="normal" 
                                 SnapsToDevicePixels="True" 
                                 Stretch="Uniform"
                                 Stroke="{TemplateBinding BorderBrush}" 
                                 Fill="{TemplateBinding Background}"/>
                            <Ellipse x:Name="CheckVisual" 
                                 SnapsToDevicePixels="True" 
                                 Fill="#1ba1e2" 
                                 Stretch="Uniform"
                                 Width="0" 
                                 Height="0"/>
                            <Path x:Name="IndeterminateVisual" Fill="White" Margin="3" Opacity="0">
                                <Path.Data>
                                    <GeometryGroup>
                                        <EllipseGeometry Center="3.5 3.5" RadiusX="3.5" RadiusY="3.5"/>
                                        <RectangleGeometry Rect="1 3 5 1"/>
                                    </GeometryGroup>
                                </Path.Data>
                            </Path>
                            <Ellipse x:Name="FocusVisual" Stroke="Gray" Opacity="0"/>
                        </Grid>
                        <ContentPresenter x:Name="Content"
                                      Grid.Column="1"
                                      Margin="{TemplateBinding Padding}"
                                      RecognizesAccessKey="True"
                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <StackPanel Orientation="Horizontal"

                            HorizontalAlignment="Left"
                            Margin="0,4,0,0">
        <RadioButton  HorizontalAlignment="Left" 
                                 IsChecked="True"
                                 Content="Not Required"
                                 Style="{StaticResource RadioButtonStyle}"
                                 GroupName="Display"/>
        <RadioButton HorizontalAlignment="Left"                                    
                                 GroupName="Display"
                                 Content="Required "
                                 Style="{StaticResource RadioButtonStyle}"
                                 Margin="35,0,0,0"/>
    </StackPanel>
</Grid>


提前感谢。

您的父级网格容器是13,您的椭圆大小是8

由于13/8=1.625,因此当它通过measure()/arrange()将其设置为水平中心时,间距不能等于内椭圆的中心,因此预计会出现偏移

因此,您的答案只是简单的数学问题,如果您希望它正确居中,请将您的
网格
父容器大小更改为可分割的大小,如
Height=“12”Width=“12”
,然后它将根据您的需要居中


希望这有帮助,干杯

谢谢chris,您的解决方案不起作用了,在更改网格为14,椭圆为8后,效果很好。但我还是不明白确切的原因。

谢谢克里斯,在网格改为14,椭圆改为8后,它的工作状态很好。