1

我正在开发一个应用程序来在翻转视图中显示带有一些元数据的照片。这一切都很好,但现在我想将 Bing 地图添加到 RichTextBlocks 并根据属于照片的 GPS 信息显示位置。为此,我需要以编程方式从 c# 代码访问 bing Maps 控件,并为当前显示的照片将地图控件的中心设置为照片的位置。到目前为止,似乎不可能从代码隐藏中访问 Bing 地图控件(名为 myMap)来做到这一点。

我尝试使用 VisualTreeHelper 并为 treeView 获取子项,但这总是返回 null。其代码类似于: var x = VisualTreeHelper.GetChild(flipView, 0); (使用 VisualRTXamlToolkit 的 Nuget 包。

这是我的 XAML 的(部分):

<Grid
        Style="{StaticResource LayoutRootStyle}"
        DataContext="{Binding Group}"      
        d:DataContext="{Binding AllGroups[0], Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}" >

        <FlipView
            x:Name="flipView"
            AutomationProperties.AutomationId="ItemsFlipView"
            AutomationProperties.Name="Item Details"
            TabIndex="1"
            Padding="0,-3,0,-3"
            Margin="-3,0,3,0"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}">

            <FlipView.ItemTemplate>
                <DataTemplate>
                    <UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates" x:Name="userControl">
                        <ScrollViewer x:Name="scrollViewer" Style="{StaticResource HorizontalScrollViewerStyle}" Grid.Row="1">

                            <!-- Three-column grid for item-detail layout -->
                            <Grid Margin="0,0,0,0" Height="Auto">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="40" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <StackPanel Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center">
                                    <ProgressRing x:Name="ProgressRing" Foreground="White" Margin="0" HorizontalAlignment="Center" IsActive="True" MaxHeight="50" MinHeight="50" MaxWidth="50" MinWidth="50"></ProgressRing>
                                    <TextBlock x:Uid="Loading" Text="Loading data" Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap" TextAlignment="Center" Padding="5" HorizontalAlignment="Center" Foreground="White" />
                                </StackPanel>

                                <Image x:Name="image" Width="Auto" Height="Auto" Margin="0,0,0,0" Stretch="Uniform" HorizontalAlignment="Right"
                                       DataContext="{StaticResource itemsViewSource}"
                                       Source="{Binding LargeImage}" Grid.Column="0" />

                                <Grid Margin="0,0,0,20" Height="Auto" Grid.Column="2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="400" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="140" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>

                                    <RichTextBlock Grid.Column="0" Grid.Row="1" Height="Auto" Padding="0,0,20,0" MaxWidth="400" OverflowContentTarget="{Binding ElementName=NextRTB1}" >
                                        <Paragraph>
                                            <Run x:Uid="AltTitle" FontSize="16" FontWeight="Bold" Text="Titel" />
                                        </Paragraph>
                                        <Paragraph Margin="0,0,0,16">
                                            <Run Text="{Binding AltTitle}" FontSize="16" FontWeight="SemiLight" />
                                        </Paragraph>
                                        <Paragraph>
                                            <Run x:Uid="Description" FontSize="16" FontWeight="Bold" Text="Omschrijving" />
                                        </Paragraph>
                                        <Paragraph>
                                            <Run x:Uid="Location" FontSize="16" FontWeight="Bold" Text="Lokatie" />
                                        </Paragraph>
                                        <Paragraph LineStackingStrategy="MaxHeight">
                                            <InlineUIContainer>
                                                <bm:Map Width="400" Height="400" ZoomLevel="6" Credentials="CREDENTIALS HERE" x:Name="myMap">
                                                    <bm:Map.Center>
                                                        <bm:Location Latitude="52" Longitude="5" />
                                                    </bm:Map.Center>
                                                </bm:Map>
                                            </InlineUIContainer>
                                        </Paragraph>
                                        <Paragraph>
                                            <Run x:Uid="CopyRight" FontSize="16" FontWeight="Bold" Text="Bronvermelding" />
                                        </Paragraph>
                                    </RichTextBlock>
                                    <RichTextBlockOverflow x:Name="NextRTB1" OverflowContentTarget="{Binding ElementName=NextRTB2}" Grid.Column="1" Grid.Row="1" Padding="20,0,20,0" MaxWidth="440" />
                                    <RichTextBlockOverflow x:Name="NextRTB2" Grid.Column="2" Grid.Row="1" Padding="20,0,20,0" MaxWidth="440" />
                                </Grid>
                            </Grid>

                            <VisualStateManager.VisualStateGroups>
                                <!-- Visual states reflect the application's view state inside the FlipView -->
                                <VisualStateGroup x:Name="ApplicationViewStates">
                                    <VisualState x:Name="FullScreenLandscape"/>
                                    <VisualState x:Name="Filled"/>

                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </ScrollViewer>
                    </UserControl>
                </DataTemplate>
            </FlipView.ItemTemplate>
        </FlipView>

        <!-- Back button -->
        <Button x:Name="backButton" Click="GoBack" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="36,56,0,0"
                    IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" 
                    Style="{StaticResource BackButtonStyle}" />

    </Grid>
4

1 回答 1

0

不能为 FlipView 绑定选中的项吗?这可能会更新另一个具有地理编码信息的属性,如下所示:

private PhotoDetail _selectedItem;
public PhotoDetail SelectedItem
{
    get{ return _selectedItem; }
    set
    {
        if (_selectedItem!= value)
        {
            _selectedItem= value;
            if(_selectedItem!=null)
                Center=new GeoCoordinate(_selectedItem.Latitude, _selectedItem.Longitude);

            NotifyPropertyChanged("SelectedItem");
        }
    }

}

private GeoCoordinate _center;
public GeoCoordinate Center
{
    get { return _center; }
    set
    {
        if (_center != value)
        {
            _center = value;
            NotifyPropertyChanged("Center");
        }
    }
}

其中 PhotoDetail 是翻转视图中照片的类型。

在您的地图中,您只需添加绑定:

Center="{Binding Center, Mode=TwoWay}"

在您的翻转视图中,您可以添加

SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
于 2013-01-11T20:04:30.607 回答