在XAML ControlTemplate中绑定图钉背景不';行不通
我的Windows Phone应用程序中使用了原色,但我似乎无法将其绑定到XAML中的图钉背景。相反,我不得不求助于在UserControl的C#代码隐藏中创建图钉 奇怪的是,我定义了另一个完全定制的图钉控件模板,它允许我绑定到原色 PrimaryColor的类型为System.Windows.Media.Color 你知道问题是什么吗 在下面的代码中,我可以在UserLocationPushpinControlTemplate中将Ellipse.Fill绑定到我的PrimaryColor,但无法在UserWaypointPushpinControlTemplate中绑定m:Pushpin.Background在XAML ControlTemplate中绑定图钉背景不';行不通,xaml,binding,windows-phone-8,bing-maps,Xaml,Binding,Windows Phone 8,Bing Maps,我的Windows Phone应用程序中使用了原色,但我似乎无法将其绑定到XAML中的图钉背景。相反,我不得不求助于在UserControl的C#代码隐藏中创建图钉 奇怪的是,我定义了另一个完全定制的图钉控件模板,它允许我绑定到原色 PrimaryColor的类型为System.Windows.Media.Color 你知道问题是什么吗 在下面的代码中,我可以在UserLocationPushpinControlTemplate中将Ellipse.Fill绑定到我的PrimaryColor,但无
<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>
尽管我一直没有弄清问题的真相,但我重构了一些代码,添加了一个样式XAML文件,其中包含以下条目:
<SolidColorBrush x:Key="PrimaryColorBrush" Color="#FF86A406" />
对于我的场景来说,这是一个更好的解决方案,但不幸的是,我的代码不再处于测试任何人可能提出的任何建议的状态。对不起