0

好的。这个应该很简单,但我找不到答案。Setter for Pushpin PositionOrigin在Visual Studio和Expression Blend中引发错误

This answer显示了如何使用样式来制作图钉,设置图钉的原点。我无法弄清楚下面的代码有什么问题。 (XMLNS应正确定义。)

<Style x:Key="OwnLocationStyle" 
     TargetType="Microsoft_Phone_Controls_Maps:Pushpin"> 
    <Setter Property="Template" Value="{StaticResource OwnLocationTemplate}"/> 
    <Setter Property="PositionOrigin" Value="BottomCenter"/> 
</Style> 

此代码运行在模拟器罚款,但给出了Expression Blend中的错误:

The property "PositionOrigin" is not a DependencyProperty. To be used in markup, non-attached properties must be exposed on the target type with an accessible instance property "PositionOrigin". For attached properties, the declaring type must provide static "GetPositionOrigin" and "SetPositionOrigin" methods.

的Visual Studio 2010提供了以下错误:对象引用未设置为一个以蓝色强调Property="PositionOrigin"的对象实例。

怎么办?我不明白为什么它会编译&运行并且编辑器会抛出错误/警告。

回答

3

好的。所以它似乎是PositionOrigin不是Pushpin风格的一部分。您需要在代码中单独设置:

OwnLocation = new Pushpin() 
{ 
    Style = App.Current.Resources["OwnLocationStyle"] as Style, 
    PositionOrigin = PositionOrigin.BottomCenter 
}; 

虽然它有点作为样式的一部分,但它很奇怪。行为与现在完全相同。

相关问题