为什么椭圆在某个比例因子上模糊?

时间:2016-10-30 22:50:08

标签: c# wpf wpf-controls

在编写简单的用户控件时,我目前面临的问题是椭圆在某个比例级别显示模糊。以下是两个不同比例级别的椭圆的屏幕截图。

enter image description here

我无法弄清问题是什么。用户控件的xaml只包含一个椭圆和一个样式(样式必须保持这样)。

<UserControl x:Class="WpfApplication8.Ball"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         DataContext="{Binding RelativeSource={RelativeSource Self}}"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">

<UserControl.Resources>
    <Style TargetType="Ellipse">
        <Setter Property="Fill" Value="Blue"/>
        <Setter Property="Stretch" Value="Uniform"/>
        <Setter Property="OpacityMask" Value="White"/>
        <Setter Property="RenderTransformOrigin" Value="0.5, 0.5"/>
        <Setter Property="Width" Value="20"/>
        <Setter Property="Height" Value="100"/>
    </Style>
</UserControl.Resources>

<Grid>
    <Ellipse>
        <Ellipse.RenderTransform>
            <TransformGroup>
                <ScaleTransform ScaleX="{Binding Scale}" ScaleY="{Binding Scale}"/>
            </TransformGroup>
        </Ellipse.RenderTransform>
    </Ellipse>            
</Grid>

在后面的代码中我有两个属性。椭圆的直径和对照所绑定的比例值。

public partial class Ball
{
    public Ball()
    {
        InitializeComponent();
    }


    private double _diameter;

    public double Diameter
    {
        get { return _diameter; }
        set
        {
            _diameter = value;
            Width = _diameter;
            Height = _diameter;
            Scale = _diameter / 100;
        }
    }


    public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register(
        "Scale",
        typeof(double),
        typeof(Ball)
    );

    public double Scale
    {
        get { return (double)GetValue(ScaleProperty); }
        set { SetValue(ScaleProperty, value); }
    }
}

现在,如果我使用直径为100和70的控件,我会在之前的屏幕截图中显示输出。我无法弄清楚为什么会出现这种情况。为什么这个小椭圆模糊不清?

<Window x:Class="WpfApplication8.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApplication8"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <local:Ball Diameter="100"/>
    <local:Ball Diameter="70"/>
</Grid>

0 个答案:

没有答案