문제

저는 현재 WPF에서 SelectionBorder라는 클래스를 구현하고 있습니다. 모양 클래스에서 파생됩니다.

기본적으로 다음과 같습니다.

public class SelectionBorder : Shape
{
   public Point StartPoint {get; set;}
   public PointCollection Points {get; set;}

   public double StrokeLength {get; set;}

   protected override Geometry DefiningGeometry{
       get{
           //Magic!
       }
   }

}

STARTPOINT 및 POINT 속성은 테두리의 모서리를 결정합니다. 테두리는 전형적인 스트로크 라인 테두리입니다 (하나의 검은 스트로크, 하나의 보이지 않는 스트로크 : ----)

내가 지금 가지고있는 문제는 코너 포인트가 자유롭게 선택할 수 있기 때문에 스트로크 수 (검은 색과 보이지 않는 스트로크를 의미하는)는 심지어 (실제로 정수조차도)가 아니라 첫 번째 스트로크가 다른 사람들 (그림에서 보입니다). 이것은 아마도 큰 문제가되지 않는 것 같습니다. 그러나 나중에 스트로크가 내용을 둘러싼 국경을 애니메이션하고 싶습니다. 이 애니메이션을 수행 할 때 정적보기의 작은 결함이 명확하게 보이고 제 생각에는 매우 혼란스러워집니다.

Alt Text http://img14.imageshack.us/img14/2874/selectionborder.png

문제는 가능한 한 원래의 스트로셀 길이에 가까워지고 균일 한 수의 스트로크를 생성하는 스트로 켈 길이를 결정하려고 시도한 것입니다. 그러나 내가 겪는 문제는 WPF (분명히)가 이중 소수점 스트로 셀 길이의 전체 정밀도를 표시 할 수 없으므로 결과 뇌졸중 수가 다시 한 번 고르지 않다는 것입니다.

이 문제에 대한 해결 방법이 있습니까? 내 문제에 대한 또 다른 해결책이 있습니까?

미리 감사드립니다!

편집 : 나는 오늘 피트니스를 위해 약간의 휴식을 취한 후 코드를 다시 테스트하고 검토했으며 결국 그것은 매우 큰 스트로 텔 길이에서만 발생합니다. 나는 작은 애니메이션 점프가 원래 생각했던 것보다 훨씬 덜 중요한 2의 Strokelengths 2를 사용할 계획입니다.

도움이 되었습니까?

해결책 2

방금 애니메이션 선택 매개지를 쉽게 만들 수있는 방법을 찾았습니다.

애니메이션을 통해 자체 제작 된 애니메이션 포인트를 움직여 애니메이션을 만드는 대신 Shape 클래스에서 기본적으로 제공 한 StrokedAshoffset 속성을 애니메이션하고 StrokedashArray를 설정하여 Strokelength를 정의합니다.

XAML에서 이렇게 보일 것입니다.

<namespace:SelectionBorder StrokeDashArray="2" AnimationDuration="0:0:1" Stroke="Black" />

수업은 다음과 같습니다.

public class SelectionBorder : Shape
{
    private DoubleAnimation m_Animation;
    private bool m_AnimationStarted;

    public SelectionBorder()
    {
        IsVisibleChanged += OnIsVisibleChanged;
    }

    protected void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        if (Visibility == Visibility.Visible)
        {
            StartAnimation();
        }
        else
        {
            StopAnimation();
        }
    }

    public void StartAnimation()
    {
        if (m_AnimationStarted)
            return;

        if (m_Animation == null)
        {
            m_Animation = CreateAnimation();
        }

        BeginAnimation(StrokeDashOffsetProperty, m_Animation);
        m_AnimationStarted = true;
    }

    protected virtual DoubleAnimation CreateAnimation()
    {
        DoubleAnimation animation = new DoubleAnimation();
        animation.From = 0;
        if (StrokeDashArray.Count == 0)
            animation.To = 4;
        else
            animation.To = StrokeDashArray.First() * 2;
        animation.Duration = AnimationDuration;
        animation.RepeatBehavior = RepeatBehavior.Forever;
        return animation;
    }

    public void StopAnimation()
    {
        if (m_AnimationStarted)
        {
            BeginAnimation(StrokeDashOffsetProperty, null);
            m_AnimationStarted = false;
        }
    }

    #region Dependency Properties

    public Duration AnimationDuration
    {
        get { return (Duration)GetValue(AnimationDurationProperty); }
        set { SetValue(AnimationDurationProperty, value); }
    }

    public static readonly DependencyProperty AnimationDurationProperty =
        DependencyProperty.Register("AnimationDuration", typeof(Duration), typeof(SelectionBorder), new UIPropertyMetadata(new Duration(TimeSpan.FromSeconds(0.5))));


    #endregion Dependency Properties

    protected override Geometry DefiningGeometry
    {
        get
        {
            double width = (double.IsNaN(Width)) ? ((Panel)Parent).ActualWidth : Width;
            double height = (double.IsNaN(Height)) ? ((Panel)Parent).ActualHeight : Height;

            RectangleGeometry geometry = new RectangleGeometry(new Rect(0, 0, width, height));

            return geometry;
        }
    }
}

다른 팁

그런 점에서 하나 이상의 코너를 "일치하지"못할 수 있습니다. 예를 들어, 한 점이 애니메이션 대시의 "소스"와 "대상"이 아닌 2 점을 선택할 수 있습니다. 하나는 "소스"이며, 대시는 2 방향으로 행진하는 것처럼 보이고, 다른 점은 대시가 수렴하고 사라지는 "대상"입니다.

예를 들어, 김프는 이런 식으로 선택한 선을 애니메이션하고 "소스"의 왼쪽 하단에 가장 가까운 점을 선택하고 "대상"의 오른쪽 상단에 가장 가까운 점을 선택하는 것 같습니다.

다른 계획도 생각해 낼 수 있습니다.

당신에게 혼란스러워 보일 수 있지만 대부분의 사용자는 신경 쓰지 않을 것임을 기억하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top