1
我正在開發一個應用程序,以在flipview中顯示具有某些元數據的照片。這一切都可以正常工作,但現在我想將一個Bing地圖添加到RichTextBlocks並根據屬於該照片的GPS信息顯示位置。爲了做到這一點,我需要以編程方式訪問c#代碼中的bing Maps控件,並且爲當前顯示的照片設置地圖控件的中心爲照片的位置。似乎不太可能從代碼隱藏中訪問Bing Maps控件(名爲myMap)來執行此操作。如何訪問XAML中的命名項目flipview
我試過使用VisualTreeHelper併爲treeView提取childs,但是這總是返回null。 該代碼看起來像這樣:var x = VisualTreeHelper.GetChild(flipView,0); (使用NuGet包的VisualRTXamlToolkit
這裏的(部分)我的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>