Expose property in Windows Phone 7 custom ControlTemplate
I'm using Visual Studio 2010 & Expression Blend 4, the target is Windows Phone 7 platform.
What I would like to make is a custom control (specifically a custom PushPin for Map, but could be anything) and expose some of it's properties so I could change them. I'll try to explain better with an example:
<ControlTemplate x:Key="PushpinControlTemplate1" TargetType="Microsoft_Phon开发者_如何学Ce_Controls_Maps:Pushpin">
<Border BorderBrush="#FF0012AD" BorderThickness="3" Background="#FF0012AD" Width="32" Height="32" CornerRadius="5">
<TextBlock Text="2" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="32" Margin="0,-4,0,0"/>
</Border>
</ControlTemplate>
This example is from MSDN example.
Now, when I "use" this template on a map, it shows as expected, but with one problem. I would like that the Text property of the TextBlock (in this case... for example it could be ImageSource if I put an image into the PushPin) could be changed in the properties panel of Expression Blend, and in the C# code "behind" the XAML - of course, for each "instance" of this PushPin separately.As far as I know, it has to do something with Dependency properties (I could be wrong?), but I am yet to find a clear example showing exactly WHAT, WHERE (C# / XAML) and WHY (sorry, I had to emphasize) had to be done.
I grasped most of the Phone 7 "topics" but now I'm a little stuck regarding resources and data bindings, as shown here :)If someone could provide some sample code or a link to a good tutorial I would be grateful. Thanks!
If you want to simply set a user control property by code, you can use a normal property. If however you want to bind to the property, you must use a dependency property.
Good example here
精彩评论