我在整个 Windows Phone 应用程序中使用了一种原色,但我似乎无法将它绑定到 XAML 中的 Pushpin.Background。相反,我不得不求助于在 UserControl 后面的 C# 代码中创建图钉。
奇怪的是,我定义了另一个完全自定义的 Pushpin ControlTemplate,它允许我绑定到原色。
PrimaryColor 的类型为 System.Windows.Media.Color
任何想法是什么问题?
在下面的代码中,我可以将 Ellipse.Fill 绑定到 UserLocationPushpinControlTemplate 中的 PrimaryColor,但我无法在 UserWaypointPushpinControlTemplate 中绑定 m:Pushpin.Background。
<UserControl x:Class="MyMap"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<UserControl.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="UserLocationPushpinControlTemplate" TargetType="m:Pushpin">
<Grid x:Name="ContentGrid" Width="34" Height="34">
<StackPanel Orientation="Vertical">
<Grid MinHeight="30" MinWidth="30">
<Ellipse Margin="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="30"
Height="30"
Stroke="White"
StrokeThickness="3">
<Ellipse.Fill>
<SolidColorBrush Color="{Binding PrimaryColor, Mode=OneWay}" />
</Ellipse.Fill>
</Ellipse>
</Grid>
</StackPanel>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="UserWaypointPushpinControlTemplate" TargetType="m:Pushpin">
<m:Pushpin Foreground="White">
<m:Pushpin.Background>
<SolidColorBrush Color="{Binding PrimaryColor, Mode=OneWay}" />
</m:Pushpin.Background>
</m:Pushpin>
</ControlTemplate>
</ResourceDictionary>
</UserControl.Resources>