Nested TabControl & Map Control Binding Issue

638
5
Jump to solution
02-14-2014 07:35 AM
BenTreptow1
New Contributor
I'm having a binding problem with the Map control when referencing a map I defined in XAML. I have a situation where I need to use nested TabControls that all reference the same map via element binding.

    <Grid x:Name="LayoutRoot">         <esri:Map x:Name="map_TestMap" WrapAround="True">             <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com:80/ArcGIS/rest/services/World_Street_Map/MapServer"/>         </esri:Map>         <sdk:TabControl x:Name="tc_1" HorizontalAlignment="Right" Width="300">             <sdk:TabItem x:Name="ti_1" Header="TabItem 1">                 <!--<nestedTabControlControls:TestControl x:Name="test_4" VerticalAlignment="Top" Map="{Binding ElementName=map_TestMap}"/>-->                 <sdk:TabControl x:Name="tc_2">                     <sdk:TabItem x:Name="ti_Nested1" Header="Nested TabItem 1">                         <nestedTabControlControls:TestControl x:Name="test_1" VerticalAlignment="Top" Map="{Binding ElementName=map_TestMap}"/>                     </sdk:TabItem>                     <sdk:TabItem x:Name="ti_Nested2" Header="Nested TabItem 2">                         <nestedTabControlControls:TestControl x:Name="test_2" VerticalAlignment="Top" Map="{Binding ElementName=map_TestMap}"/>                     </sdk:TabItem>                 </sdk:TabControl>             </sdk:TabItem>             <sdk:TabItem x:Name="ti_2" Header="TabItem 2">                 <nestedTabControlControls:TestControl x:Name="test_3" VerticalAlignment="Top" Map="{Binding ElementName=map_TestMap}"/>             </sdk:TabItem>         </sdk:TabControl>     </Grid>


Everything above works fine except for the last TestControl (test_3) does not get a value for the property "Map". It's null. However, if I comment out the nested TabControl (tc_2) and uncomment TestControl "test_4" everything will work as expected.

There seems to be something with element binding to the map in a nested TabControl that prevents element binding to the map on subsequent controls.

Any ideas?

TestControl:

using System.Windows; using System.Windows.Controls; using ESRI.ArcGIS.Client;  namespace NestedTabControl.Controls {     [TemplatePart(Name = TestControl.MapNameElementName, Type = typeof(TextBlock))]     public class TestControl : Control     {         private const string MapNameElementName = "txt_Map";          public const string MapPropertyName = "Map";          public TestControl()         {             this.DefaultStyleKey = typeof(TestControl);         }          private TextBlock _txtMap;          public static readonly DependencyProperty MapProperty = DependencyProperty.Register(MapPropertyName, typeof(Map), typeof(TestControl), new PropertyMetadata(OnMapPropertyChanged));          private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)         {             (d as TestControl).OnMapPropertyChanged(e.NewValue, e.OldValue);         }          private void OnMapPropertyChanged(object newValue, object oldValue)         {             if (_txtMap != null)                 _txtMap.Text = ((Map)newValue).Name;         }          public override void OnApplyTemplate()         {             base.OnApplyTemplate();              _txtMap = GetTemplateChild(MapNameElementName) as TextBlock;         }          public Map Map         {             get { return (Map)GetValue(MapProperty); }             set { SetValue(MapProperty, value); }         }     } }
0 Kudos
1 Solution

Accepted Solutions
AnargyrosTomaras
New Contributor III
Nope. I'm pretty confident it's an issue with the Map control though. I'm hoping someone from ESRI can shed some light on this.


It doesn't have anything to do with the Map or ESRI's API in general. It's purely a Silvelight XAML issue specifically with nested TabControls. I noticed that it does not work when you use a direct binding but instead works if i use a Path. When i changed the binding to {Binding Path=Name, ElementName=map_TestMap} it worked. I am not sure what's really going on there.

Here's a workaround for you though:

 <sdk:TabControl x:Name="tc_SidePanel" HorizontalAlignment="Right" Width="300">    <sdk:TabControl.Resources>  <ContentControl x:Key="IShouldNotHaveToDoThis" Tag="{Binding ElementName=map_TestMap}"/>  </sdk:TabControl.Resources> 


and then inside your nested control bind the Map this way :

 <nestedTabControlControls:TestControl x:Name="test_5"            VerticalAlignment="Top"            Map="{Binding Tag, Source={StaticResource IShouldNotHaveToDoThis}}"            Test="{Binding Text, ElementName=txt_TestValue}"/> 


Let me know if it works for you.

Anargyros

View solution in original post

0 Kudos
5 Replies
MitchellWiniecki
New Contributor II
This is almost the exact same thing I'm experiencing!
It seems like element binding in a nested TabControl is limited in some way??
0 Kudos
KeithAnderson
New Contributor III
Did this ever work for you?
0 Kudos
BenTreptow1
New Contributor
Did this ever work for you?


Nope. I'm pretty confident it's an issue with the Map control though. I'm hoping someone from ESRI can shed some light on this.
0 Kudos
AnargyrosTomaras
New Contributor III
Nope. I'm pretty confident it's an issue with the Map control though. I'm hoping someone from ESRI can shed some light on this.


It doesn't have anything to do with the Map or ESRI's API in general. It's purely a Silvelight XAML issue specifically with nested TabControls. I noticed that it does not work when you use a direct binding but instead works if i use a Path. When i changed the binding to {Binding Path=Name, ElementName=map_TestMap} it worked. I am not sure what's really going on there.

Here's a workaround for you though:

 <sdk:TabControl x:Name="tc_SidePanel" HorizontalAlignment="Right" Width="300">    <sdk:TabControl.Resources>  <ContentControl x:Key="IShouldNotHaveToDoThis" Tag="{Binding ElementName=map_TestMap}"/>  </sdk:TabControl.Resources> 


and then inside your nested control bind the Map this way :

 <nestedTabControlControls:TestControl x:Name="test_5"            VerticalAlignment="Top"            Map="{Binding Tag, Source={StaticResource IShouldNotHaveToDoThis}}"            Test="{Binding Text, ElementName=txt_TestValue}"/> 


Let me know if it works for you.

Anargyros
0 Kudos
BenTreptow1
New Contributor
atomaras,

This indeed works.. Excellent workaround! Thank for the suggestion.
0 Kudos