Click here to Skip to main content
15,065,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to create a style that is to be applied to a Bing Map PushPin control. But I need to set the location of the Pushpin from the page where the control is implemented (like templateBinding) and not in the style. The control template in the style will be applied on an infobox which will be bound to the location which the pushpin is placed in the main page.
When I am not creating a style and adding the template in the mainpage itself, I am getting the bound values i.e the Latitude and Longitude. But when I am putting it in a style in a resource dictionary, I am not getting the bound fields. What should be the correction made here in the resource dictionary file. PFB the style :-
XML
<!--Style for PushPin-->
<Style x:Key="myPushpinStyle" TargetType="m:Pushpin">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <m:Pushpin Name="myPin" Background="{TemplateBinding Property=Background}">
                <ToolTipService.ToolTip>
                    <ToolTip Focusable="True" Opacity="50">
                        <ToolTip.Template>

                            <ControlTemplate>
                                <Border CornerRadius="5" Width="180" Height="auto" MinHeight="60" Opacity="50" ToolTipService.ShowDuration="12000">
                                    <Border.Background>
                                        <LinearGradientBrush>
                                            <GradientStop Color="#DAFDA7" Offset="0"/>
                                            <GradientStop Color="Green" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="20"></RowDefinition>
                                            <RowDefinition Height="20"></RowDefinition>
                                            <RowDefinition Height="20"></RowDefinition>
                                            <RowDefinition Height="30*"></RowDefinition>
                                        </Grid.RowDefinitions>

                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition></ColumnDefinition>
                                            <ColumnDefinition></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Row="0" FontSize="12" FontWeight="Bold">Information</TextBlock>
                                        <TextBlock Grid.Row="1" VerticalAlignment="Top">Latitude</TextBlock>
                                        <TextBlock Grid.Row="2" VerticalAlignment="Top">Longitude</TextBlock>
                                        <TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Top">
                                            <TextBlock.Text>
                                                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type m:Pushpin}}" Path="Location.Latitude">
                                                    </Binding>
                                                </TextBlock.Text>
                                        </TextBlock>
                                        <TextBlock Grid.Row="2" Grid.Column="1" VerticalAlignment="Top">
                                            <TextBlock.Text>
                                                <Binding Path="Location.Longitude">
                                                    <Binding.RelativeSource>
                                                        <RelativeSource Mode="Self"/>
                                                    </Binding.RelativeSource>
                                                </Binding>
                                            </TextBlock.Text>
                                        </TextBlock>
                                    </Grid>
                                </Border>
                            </ControlTemplate>
                        </ToolTip.Template>
                    </ToolTip>
                </ToolTipService.ToolTip>
                </m:Pushpin>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Posted
Comments
stibee 24-Jun-13 12:12pm
   
Does only the binding didn't run? Does the rest of the style run?
Jashobanta 25-Jun-13 1:21am
   
The rest of style runs. But the binding is showing blank text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900