<local:WidgetControl x:Name="MyWidget" DataContext="{Binding ElementName=MyMap}"/>
<ComboBox x:Name="MyComboBox" ItemsSource="{Binding Layers}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ID}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
#region Dependancy Properties
protected static readonly DependencyProperty MapProperty=
DependencyProperty.Register("Map", typeof(Map), typeof(YourUserControlName), new PropertyMetadata(OnMapPropertyChanged));
public Map Map
{
get { return (Map)this.GetValue(MapProperty); }
set
{
this.SetValue(MapProperty, (DependencyObject)value);
}
}
private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as YourUserControlName).PopulateLayerList();
}
private void PopulateLayerList()
{
if (this.Map != null)
{
//populate your layer list here
}
}
#endregion
Hi Ann,
One way to acheive this could be using Dependancy Property in your UserControl:#region Dependancy Properties protected static readonly DependencyProperty MapProperty= DependencyProperty.Register("Map", typeof(Map), typeof(YourUserControlName), new PropertyMetadata(OnMapPropertyChanged)); public Map Map { get { return (Map)this.GetValue(MapProperty); } set { this.SetValue(MapProperty, (DependencyObject)value); } } private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as YourUserControlName).PopulateLayerList(); } private void PopulateLayerList() { if (this.Map != null) { //populate your layer list here } } #endregion
Then your UserControl declaration in xaml will be:
[HTML]
<local:WidgetControl x:Name="MyWidget" Map="{Binding ElementName=MyMap}"/>
[/HTML]
I haven't tested it your scenario and there might be a better approach, but it might be worth trying.
Good Luck!
This binding can't work if 'MyMap' is not in the same xaml file.
<esri:Legend Map="{Binding ElementName=MyMap}"
<esri:Legend Map="{TemplateBinding Map}" .....
<local:LegendDialog x:Name="MyLegendDialog" Canvas.Left="430" Canvas.Top="200" Height="225" Width="218" Visibility="Collapsed"
Map="{Binding ElementName=MyMap}"
/>
I get the following error..........The property 'Map' was not found in type LegendDialog
protected static readonly DependencyProperty MapProperty =
DependencyProperty.Register("Map", typeof(Map), typeof(LegendDialog), new PropertyMetadata(OnMapPropertyChanged));
public Map Map
{
get { return (Map)this.GetValue(MapProperty); }
set
{
this.SetValue(MapProperty, (DependencyObject)value);
MessageBox.Show("in the GetValue(MapProperty");
}
}
private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show("in the OnMapPropertyChanged");
}
not sure what was needed in the private void PopulateLayerList()