我目前正在将一个项目从Windows Phone 8.1迁移到UWP,我遇到的问题是,当代码中的renderTransform compositeTransform旋转时,XAML行不会旋转,但如果在XAML中进行了更改,则会发生。在Windows Phone 8.1中,它没有任何问题。
这是XAML部分:
<Maps:MapControl
<Line x:Name="mapLineMilestoneHelper"
Stroke="Black" StrokeThickness="2" Opacity="1.0" StrokeDashArray="2,2"
RenderTransformOrigin="0.5, 0.5"
X1="0" Y1="-1000" X2="0" Y2="1000" Visibility="Collapsed">
<Line.RenderTransform>
<CompositeTransform x:Name="lineMilestoneHelperAzimuth" Rotation="90.0"/>
<!--<RotateTransform x:Name="lineMilestoneHelperAzimuth"
CenterX="0.5" CenterY="0.5" Angle="0"/>-->
</Line.RenderTransform>
</Line>
</Maps:MapControl
此行在地图控件中绘制。然后在代码中更改(但是我将旋转值更改为0,它不会旋转。
以下是应该旋转上面的XAML行的C#代码:
lineMilestoneHelperAzimuth.Rotation = azimuth;
正如您所看到的,我也尝试过使用RotateTransform,但它没有用。
知道为什么会这样吗?
谢谢
答案 0 :(得分:0)
根据https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi#add-a-line,您可以从代码中向地图添加行。 我假设这是因为你可以通过这种方式指定元素在地图上的位置(可能在地理坐标中),以便在平移和缩放地图时随地图移动。
另一种方法,如果您正在寻找一种覆盖类型的设置(如平视显示器):将地图嵌套在网格中并将该线作为兄弟放置到网格中的地图中:
我做了一个最小的工作示例。注意更改的线坐标并将“可见性”设置为“可见”而不是“折叠”以将线条置于视图中并使其可见。我还使用了硬编码的画笔和线条粗细。
<Page xmlns:my="using:Windows.UI.Xaml.Controls.Maps"
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<my:MapControl/>
<Line x:Name="mapLineMilestoneHelper"
Stroke="Aqua"
StrokeThickness="5"
Opacity="1.0"
StrokeDashArray="2,2"
RenderTransformOrigin="0.5, 0.5"
X1="0"
Y1="0"
X2="700"
Y2="500"
Visibility="Visible">
<Line.RenderTransform>
<CompositeTransform x:Name="lineMilestoneHelperAzimuth"
Rotation="90.0" />
<!--<RotateTransform x:Name="lineMilestoneHelperAzimuth" CenterX="0.5" CenterY="0.5" Angle="0" />-->
</Line.RenderTransform>
</Line>
<Button Content="Button"
HorizontalAlignment="Left"
Margin="64,80,0,0"
VerticalAlignment="Top"
Click="Button_Click" />
</Grid>
</Page>
在代码隐藏中:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
lineMilestoneHelperAzimuth.Rotation = 45;
}
}
答案 1 :(得分:0)
如果你想在地图上以地图移动的地图上绘制一条线,建议使用MapPolyine而不是XAML https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.Maps.MapPolyline
它会表现更好并坚持使用地图beter(XAML会相对于地图漂移)。