Как мне масштабировать сегмент дуги в XAML без использования Viewbox - PullRequest
0 голосов
/ 03 ноября 2019

Я бы хотел масштабировать сегмент дуги аналогично тому, как масштабируется сегмент линии. Я не хочу использовать Viewbox, так как это увеличит / уменьшит толщину линии при изменении размера окна. В моем примере у меня есть сегмент линии, который масштабируется соответствующим образом, и я хотел бы аналогичным образом масштабировать сегмент дуги. Как это можно сделать в XAML?

<UserControl x:Class="TMUI.UserControls.Chart"
        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" 
        xmlns:local="clr-namespace:TMUI"
        xmlns:c="clr-namespace:TMUI.Converters"
        xmlns:bc="clr-namespace:TMUI.BindingConverters"
        xmlns:vm="clr-namespace:TMUI.ViewModels"
        mc:Ignorable="d"
        Visibility="{Binding BBMainMenuVisibility}" >

<Grid x:Name="grid" Background="Black">
    <Grid.Resources>
        <ScaleTransform x:Key="transform"
                    ScaleX="{Binding ActualWidth, ElementName=grid}"
                    ScaleY="{Binding ActualHeight, ElementName=grid}"/>
    </Grid.Resources>
    <Path Stroke="White" StrokeThickness="1">
        <Path.Data>
            <LineGeometry StartPoint="0.01,0.01" EndPoint="0.99,0.99"
                        Transform="{StaticResource transform}"/>
        </Path.Data>
    </Path>

    <Path Stroke="White" StrokeThickness="1">
        <Path.Data>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigureCollection>
                        <PathFigure StartPoint="10,20">
                            <PathFigure.Segments>
                                <PathSegmentCollection>
                                    <ArcSegment Size="40,30" RotationAngle="45" IsLargeArc="True" SweepDirection="CounterClockwise" Point="100,100"/>
                                </PathSegmentCollection>
                            </PathFigure.Segments>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry.Figures>
            </PathGeometry>
        </Path.Data>
    </Path>
</Grid>    

1 Ответ

1 голос
/ 03 ноября 2019

Вы бы масштабировали PathGeometry так же, как вы масштабировали LineGeometry, то есть, назначая ScaleTransform для его свойства Transform.

Когда вы используете тот же ScaleTransform, что и для LineGeometry, вам также потребуетсячтобы использовать тот же диапазон координат от 0 до 1.

<Path Stroke="White" StrokeThickness="1">
    <Path.Data>
        <PathGeometry Transform="{StaticResource transform}">
            <PathGeometry.Figures>
                <PathFigureCollection>
                    <PathFigure StartPoint="0.1,0.2">
                        <PathFigure.Segments>
                            <PathSegmentCollection>
                                <ArcSegment Size="0.4,0.3" Point="1,1"
                                            RotationAngle="45" IsLargeArc="True"
                                            SweepDirection="CounterClockwise"/>
                            </PathSegmentCollection>
                        </PathFigure.Segments>
                    </PathFigure>
                </PathFigureCollection>
            </PathGeometry.Figures>
        </PathGeometry>
    </Path.Data>
</Path>

Вы также можете нарисовать один путь с несколькими геометриями в GeometryGroup:

<Path Stroke="White" StrokeThickness="1">
    <Path.Data>
        <GeometryGroup Transform="{StaticResource transform}">
            <LineGeometry StartPoint="0.01,0.01" EndPoint="0.99,0.99"/>
            <PathGeometry>
                <PathGeometry.Figures>
                    ...
                </PathGeometry.Figures>
            </PathGeometry>
        </GeometryGroup>
    </Path.Data>
</Path>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...