Ok. This one should be simple but I cannot find the answer.
This answer shows how to use Styles for pushpins, esp. to set the origin of the pushpin. I cannot figure out what's wrong with the following code. (XMLNS should be defined properly.)
<Style x:Key="OwnLocationStyle"
TargetType="Microsoft_Phone_Controls_Maps:Pushpin">
<Setter Property="Template" Value="{StaticResource OwnLocationTemplate}"/>
<Setter Property="PositionOrigin" Value="BottomCenter"/>
</Style>
This code runs fine on emulator but gives an error in 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 gives the following error: Object reference not set to an instance of an object underlining Property="PositionOrigin"
in blue.
What to do? I can't understand why it compiles & runs and the editors throw errors/warnings.
OK. So it seems to be that PositionOrigin isn't part of Pushpin's style. You need to set it separately in code:
OwnLocation = new Pushpin()
{
Style = App.Current.Resources["OwnLocationStyle"] as Style,
PositionOrigin = PositionOrigin.BottomCenter
};
It's strange though that it kinda worked as part of style. The behavior was exactly the same as now.