Winrt - 在Bing Map上将值绑定到纬度和经度

时间:2015-07-25 19:23:07

标签: c# xaml windows-runtime windows-store-apps

我有这个包含Map

的DataTemplate
<DataTemplate x:Key="MyMeetingsWithMapSquares">


        <Grid Width="350" Height="290" DataContext="{Binding}" >
            <StackPanel >
                <StackPanel.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0,1"  >
                        <GradientStop Color="#FF0072C6" Offset="0"/>
                        <GradientStop Color="#FF008FD4" Offset="1"/>
                    </LinearGradientBrush>
                </StackPanel.Background>

                <Grid DataContext="{Binding}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="90"/>
                        <RowDefinition Height="60"/>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="150"/>
                    </Grid.RowDefinitions>
                    <Border BorderBrush="#0166a0" BorderThickness="0,0,0,1" Margin="10,0,10,0">
                        <StackPanel Grid.Row="0">

                            <Grid DataContext="{Binding}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="220"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid Grid.Column="0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="50"/>
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Grid.Row="0" Margin="0,16,0,0" Text="{Binding MyMeetingSquareDayNumber}" Width="40" FontFamily="Segoe UI Semibold" FontSize="33" FontWeight="SemiBold" VerticalAlignment="Top"/>
                                        <TextBlock Grid.Row="0" Margin="0,16,0,0" Text="{Binding MyMeetingSquareMonthText}" Width="60" FontFamily="Segoe UI Regular" FontSize="33" FontWeight="Normal" VerticalAlignment="Top"/>
                                        <TextBlock Grid.Row="0" Margin="0,16,0,0" Text="{Binding MyMeetingSquareYearText}"  Width="60" FontFamily="Segoe UI Light" FontSize="33" FontWeight="Light" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                    </StackPanel>
                                    <TextBlock Grid.Row="1" Margin="0,5,0,0" Text="Business meeting" FontFamily="Segoe UI Semibold" FontSize="24" FontWeight="SemiBold" VerticalAlignment="Center"/>
                                </Grid>
                                <StackPanel Grid.Column="1" VerticalAlignment="Center">
                                    <TextBlock Text="{Binding MyMeetingSquareDayHour}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0"/>
                                </StackPanel>
                            </Grid>

                        </StackPanel>
                    </Border>
                    <Border Grid.Row="1" BorderBrush="#0166a0" BorderThickness="0,0,0,1" Margin="10,0,10,0">
                        <StackPanel >
                            <TextBlock Text="{Binding MyMeetingSquareSummary}" FontFamily="Segoe UI Light" FontSize="16" Margin="0,10,0,10" TextWrapping="Wrap"/>
                        </StackPanel>
                    </Border>
                    <StackPanel Grid.Row="2">
                        <Border BorderBrush="#0166a0" BorderThickness="0,0,0,1" Margin="10,0,10,0">
                            <ScrollViewer VerticalScrollBarVisibility="Hidden" VerticalScrollMode="Disabled" HorizontalScrollBarVisibility="Hidden" HorizontalScrollMode="Enabled">
                                <GridView ItemContainerStyle="{StaticResource GridViewItemStyle2}" ItemsSource="{Binding MyMeetingsSquareUsers}"  ItemTemplateSelector="{StaticResource meetingSelector}" Grid.Row="1" Margin="0,10,0,0"  SelectionMode="None" HorizontalContentAlignment="Left" VerticalContentAlignment="Bottom">
                                    <GridView.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <ItemsWrapGrid Orientation="Vertical" MaximumRowsOrColumns="1"/>
                                        </ItemsPanelTemplate>
                                    </GridView.ItemsPanel>
                                </GridView>
                            </ScrollViewer>
                        </Border>
                    </StackPanel>
                    <StackPanel Grid.Row="3" Height="150" DataContext="{Binding}">
                        <Maps:Map Tag="{Binding MyMeetingSquareLat}"  Margin="0,10,0,0"  DoubleTappedOverride="Map_DoubleTappedOverride" ShowBreadcrumb="False" Height="150" ShowNavigationBar="False"  ShowScaleBar="False" ShowTraffic="False" Width="350" Credentials="AnZKLHgAfKSwa5BAB2Kr-g8KENJBm1US3txxxxxxzCDUAgxhgJZVXyUgRIwM" ViewChanged="Map_ViewChanged" >
                            <Maps:Map.Center>
                                <Maps:Location Latitude="{Binding MyMeetingSquareLat}" Longitude="{Binding MyMeetingSquareLng}"/>
                            </Maps:Map.Center>
                        </Maps:Map>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </Grid>
    </DataTemplate>

我试图将值绑定到它的纬度和经度,但由于某种原因它们总是0.我尝试将其中一个值绑定到Map标签并且它起作用,标签是49.597378但是纬度为0。

如何将值传递给map lat和lng?

修改

所以我改变了我的代码并添加了一个图钉

<StackPanel Grid.Row="3" Height="150" DataContext="{Binding}">
                        <Maps:Map Tag="{Binding MyMeetingSquareLat}" DataContext="{Binding}" ZoomLevel="5"  Margin="0,10,0,0"  DoubleTappedOverride="Map_DoubleTappedOverride" ShowBreadcrumb="False" Height="150" ShowNavigationBar="False"  ShowScaleBar="False" ShowTraffic="False" Width="350" Credentials="AnZKLHgAfKSwa5BAB2Kr-g8KENJBmxxxxxxyOCEwbJzCDUAgxhgJZVXyUgRIwM" ViewChanged="Map_ViewChanged" >
                            <Maps:Map.Center>
                                <Maps:Location Latitude="{Binding MyMeetingSquareLat}" Longitude="{Binding MyMeetingSquareLng}"/>
                            </Maps:Map.Center>
                            <Maps:Map.Children>
                                <Maps:Pushpin >
                                    <Maps:Pushpin.Background>
                                        <ImageBrush Stretch="Fill" ImageSource="ms-appx:///Assets/Pdf/edit.png"/>
                                    </Maps:Pushpin.Background>
                                    <Maps:MapLayer.Position>
                                        <Maps:Location Latitude="{Binding MyMeetingSquareLat}" Longitude="{Binding MyMeetingSquareLng}" />
                                    </Maps:MapLayer.Position>
                                </Maps:Pushpin>
                            </Maps:Map.Children>
                        </Maps:Map>
                    </StackPanel>
                </Grid>
            </StackPanel>

图钉显示在正确的位置,但地图中心继续转到0 0点,由于某种原因它没有读取绑定值。

1 个答案:

答案 0 :(得分:0)

您正在将字符串(正如您在评论中所述)绑定到Latitude的{​​{1}}属性。但是Maps:Location期望此值为Maps:Location

您需要使用以下代码将此值转换为double:

double

如果值Double.Parse(myStringValue); 无法更改为字符串本身,则添加另一个属性,然后绑定到它:

MyMeetingSquareLat