UWP Масштаб эллипса плавно? - PullRequest
0 голосов
/ 21 января 2020

Привет У меня есть случай, когда пользователь должен иметь возможность масштабировать эллипс, выбрав штрих (границу) эллипса. Я попытался использовать событие формы Pointer Pressed и Pointermove для достижения этой цели. Но масштабирование не является непрерывным (плавным). У любого есть представление о том, как лучше достичь этого. Это очень поможет, спасибо

private void PostureDifficultyPath_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
        Path selectedPath = sender as Path;
        if (selectedPath != null)
        {
            selectedPath.Stroke = new SolidColorBrush(Colors.DarkBlue);
            PointerPoint ptrPt = e.GetCurrentPoint(selectedPath);
            mousePressedPoint = new Point(ptrPt.Position.X, ptrPt.Position.Y);
        }
        e.Handled = true;
    }
private void PostureDifficultyPath_PointerMoved(object sender, PointerRoutedEventArgs e)
    {
        Pointer ptr = e.Pointer;
        double mouseCurrentPosition;
        if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
        {
            PointerPoint ptrPt = e.GetCurrentPoint(DifficultyUpperPath);
            if (ptrPt.Properties.IsLeftButtonPressed)
            {//this is a variable which i update using mvvm
               //this scale factor should be like a value which makes smooth scaling
                ScaleFactor -= 0.1111411;//
            }
            else { mouseCurrentPosition= ptrPt.Position.X; }
        }
        e.Handled = true;
    }


 <Path>
            <Path.Data>
                <PathGeometry>
                    <PathFigure  x:Name="UpperCircle" StartPoint="{x:Bind UpperStartPoint,Mode=TwoWay }">
                        <ArcSegment IsLargeArc="True" x:Name="UpperArc"
                            Size="{x:Bind UpperArcRadius,Mode=TwoWay}"
                            Point="{x:Bind UpperArcEndPoint,Mode=TwoWay}"
                            SweepDirection="Clockwise" />
                    </PathFigure>
                </PathGeometry>
            </Path.Data>
            <Path.RenderTransform>
                <ScaleTransform 
                                 CenterX="125" CenterY="100"   
                                 ScaleX="{x:Bind ScaleFactor,Mode=TwoWay}"
                                 ScaleY="{x:Bind ScaleFactor,Mode=TwoWay}"/>
            </Path.RenderTransform>
        </Path>

1 Ответ

1 голос
/ 21 января 2020

Вы можете попробовать использовать Storyboard для сглаживания преобразования Scale.

xaml

<Page.Resources>
    <Storyboard x:Name="ScaleStoryboard">
        <DoubleAnimation x:Name="ScaleXAnimation" Duration="0:0:0.5" Storyboard.TargetName="CompositeTransform"
                         Storyboard.TargetProperty="ScaleX"/>
        <DoubleAnimation x:Name="ScaleYAnimation" Duration="0:0:0.5" Storyboard.TargetName="CompositeTransform"
                         Storyboard.TargetProperty="ScaleY"/>
    </Storyboard>
</Page.Resources>

...

<Path>
    ...
   <Path.RenderTransform>
       <ScaleTransform 
                    CenterX="125" CenterY="100"   
                    x:Name="EllipseScaleTransform"/>
   </Path.RenderTransform>
    ...
</Path>

...

xaml.cs

private void PostureDifficultyPath_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    // other code
    ScaleXAnimation.To = ScaleYAnimation.To = MyScale;
    ScaleStoryboard.Begin();
    e.Handled = true;
}

С уважением.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...