Why is it my reference to an existing map control isn't working?
- My main page loads another page inside the main page Grid
- The loaded page is a TabView containing a few TabViewItems
- In 1 of the TabViewItems there is a MapControl
- I want to access the MapControl dynamically to add markers to it
I tried using MapControl mapControl = pageMap.MyMapControl;
but it's not working. Why?
MainPage.xaml
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Text="Hello World" />
</StackPanel>
<controls:TabView
x:FieldModifier="public"
Grid.Row="1"
x:Name="MainTabs"
TabWidthBehavior="Actual"
CanCloseTabs="False"
IsCloseButtonOverlay="False"
CanDragItems="False"
CanReorderItems="False"
AllowDrop="False">
</controls:TabView>
</Grid>
MainPage.xaml.cs
public sealed partial class MainPage: Page
{
public MainPage()
{
this.InitializeComponent();
var mapPage= new MapPage();
TabView tabView = mainPage.MainTabs;
var tab1 = new TabViewItem { Header = "Map" };
tabView.Items.Add(tab1);
var tab2 = new TabViewItem { Header = "Tab 2" };
tabView.Items.Add(tab2);
var tab3 = new TabViewItem { Header = "Tab 3" };
tabView.Items.Add(tab3);
tabView.SelectedItem = tab1;
// 1st tab contents
var mapPage = new MapPage();
MapControl mapControl = pageMap.MyMapControl; ??
tab1.Content = mapPage;
MainGrid.Children.Add(pageTabs);
}
}
Map page
<Grid x:Name="MapGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Maps:MapControl
Grid.Row="0"
x:Name="MyMapControl"
MapServiceToken="[token]"
ZoomLevel="8"/>
</Grid>