Wpf 如何在不使用Viewbox的情况下在XAML中缩放arcsegment
我希望缩放圆弧段的方式与缩放线段的方式类似。我不想使用Viewbox,因为这会随着窗口大小的调整而增加/减少线条厚度。在我的示例中,我有一个适当缩放的线段,我希望以类似的方式缩放圆弧段。如何在XAML中实现这一点Wpf 如何在不使用Viewbox的情况下在XAML中缩放arcsegment,wpf,xaml,Wpf,Xaml,我希望缩放圆弧段的方式与缩放线段的方式类似。我不想使用Viewbox,因为这会随着窗口大小的调整而增加/减少线条厚度。在我的示例中,我有一个适当缩放的线段,我希望以类似的方式缩放圆弧段。如何在XAML中实现这一点 <UserControl x:Class="TMUI.UserControls.Chart" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="ht
<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>
可以使用与缩放线条几何体相同的方式缩放路径几何体,即通过将ScaleTransform指定给其
Transform
属性来缩放路径几何体
使用与线形几何图形相同的比例变换时,还需要使用从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>
...
谢谢。当我建立和运行的弧显示良好。是否有原因使我无法在设计视图中看到渲染的圆弧?此外,如果注释掉XAML的linegeometry部分并保留arcsegment部分,则设计视图将在设计视图中显示从上到下跳过的圆弧。这种行为很奇怪。出现渲染问题的原因似乎是圆弧超出了线段定义的边界。如果我将“大小”更改为“0.3,0.4”,并指向“0.7,0.9”,并将扫掠方向更改为“顺时针”,则圆弧在边界内,并且没有任何渲染问题。