Dear All
i m working on addins.On my dockpane i have one drop down.i want to get all layer on drawComplete map event.After completion of draw event i check all there layers are in observable collection.But when i checked my drop down i did not find any layer there.please help.Actually this is my first addin in ArcGIS pro SDK.
Thanks,
-------------------------MY VIEW-----------------------------
<DockPanel Grid.Column="0" Grid.ColumnSpan="1" Grid.RowSpan="1" Grid.Row="0" FlowDirection="RightToLeft" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Visible">
<Grid x:Name="panelGrid" Background="Transparent" Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="12*"></RowDefinition>
<RowDefinition Height="12*"></RowDefinition>
<RowDefinition Height="76*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Content="hhh" Width="30" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" Margin="5,5,5,5"/>
<ComboBox Width="400" Height="30" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="1" Grid.Row="0" Margin="5,5,5,5" ItemsSource="{Binding ddMapLayers}">
</ComboBox>
</Grid>
------------------My VIEW MODEL--------------------------------------
internal class MainDockpaneViewModel : DockPane
{
private const string _dockPaneID = "ProMOPConfigTool_MainDockpane";
private const string _menuID = "ProMOPConfigTool_MainDockpane_Menu";
private readonly object _lockCollection = new object();
public event PropertyChangedEventHandler PropertyChanged;
//***************************************************************//
private bool _subscribed;
private object _lock = new object();
//***************************************************************//
private ObservableCollection<string> _ddMapLayers;
public System.Collections.ObjectModel.ObservableCollection<string> ddMapLayers
{
get { return _ddMapLayers; }
set
{
_ddMapLayers = value;
OnPropertyChanged("ddMapLayers");
}
}
protected MainDockpaneViewModel() {
ddMapLayers = new ObservableCollection<string>();
Utils.RunOnUiThread(() =>
{
BindingOperations.EnableCollectionSynchronization(ddMapLayers, _lockCollection);
});
}
//****************************************************************************************************************************//
protected override void OnShow(bool isVisible)
{
if (isVisible)
{
//Module1.Current.DefFilterVM = this;
if (!_subscribed)
{
_subscribed = true;
// connect to events
ArcGIS.Desktop.Mapping.Events.DrawCompleteEvent.Subscribe(OnDrawComplete);
}
}
else
{
if (_subscribed)
{
_subscribed = false;
// unsubscribe from events
//ArcGIS.Desktop.Mapping.Events.ActiveMapViewChangedEvent.Unsubscribe(OnActiveMapViewChanged);
ArcGIS.Desktop.Mapping.Events.DrawCompleteEvent.Unsubscribe(OnDrawComplete);
}
}
base.OnShow(isVisible);
}
private async void OnDrawComplete(MapViewEventArgs obj)
{
MapView mapView = MapView.Active;
try
{
if (obj == null)
return;
var mapItem = obj.MapView.Map as Map;
if (mapItem == null)
return;
ddMapLayers.Clear();
if (mapView == null)
System.Windows.MessageBox.Show("Null");
else
{
//for (int i = 0; i < MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().ToList().Count; i++)
await QueuedTask.Run(() =>
{
if (mapView == null)
System.Windows.MessageBox.Show("Null");
else
{
ddMapLayers =LoopThroughLayersAndLoadSelectablelayersOfSpecificUIDAsync(MapView.Active.Map).Result;
}
});
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
}
public async Task<ObservableCollection<string>> LoopThroughLayersAndLoadSelectablelayersOfSpecificUIDAsync(Map map)
{
ObservableCollection<string> ddColl = null;
//try
//{
ddColl=new ObservableCollection<string>();
return await QueuedTask.Run(() =>
{
for (int i = 0; i < map.GetLayersAsFlattenedList().OfType<FeatureLayer>().ToList().Count; i++)
{
var layer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().ToList()[i];
ddColl.Add(layer.Name.Replace("_", " "));
}
MessageBox.Show(ddColl.Count.ToString());
return ddColl;
});
//}
//catch (Exception ex)
//{
// string strex = ex.Message.ToString();
// System.Windows.MessageBox.Show("No layers of type: " + strex.ToString()); //uid.Value.ToString
//}
//finally
//{
//}
}
private void OnActiveMapViewChanged(ActiveMapViewChangedEventArgs obj)
{
//Module1.Current.DefFilterVM = this; //Remove this.
//GetMapMembers(MapView.Active);
//InitializeFilters();
}
public void OnMapMemberPropertiesChanged(MapMemberPropertiesChangedEventArgs obj)
{
//if (SelectedMapMember == null)
// return;
//if (obj.MapMembers.Contains(SelectedMapMember))
// InitializeFilters();
}
//*****************************************************************************************************************************//
/// <summary>
/// Show the DockPane.
/// </summary>
internal static void Show()
{
DockPane pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
if (pane == null)
return;
pane.Activate();
}
/// <summary>
/// Text shown near the top of the DockPane.
/// </summary>
private RelayCommand _DrawCircleButton_2;
public ICommand DrawCircleButton_2
{
get
{
if (_DrawCircleButton_2 == null)
{
_DrawCircleButton_2 = new RelayCommand(OnClick, true);
}
return _DrawCircleButton_2;
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
{
var handler = PropertyChanged;
handler?.Invoke(this, args);
}
public void OnClick()
{
try
{
System.Windows.MessageBox.Show("You Click Draw 2");
}
catch (Exception ex) {
Console.Write(ex.InnerException.ToString());
}
}
private string _heading = "My DockPane";
public string Heading
{
get { return _heading; }
set
{
SetProperty(ref _heading, value, () => Heading);
}
}
#region Burger Button
/// <summary>
/// Tooltip shown when hovering over the burger button.
/// </summary>
public string BurgerButtonTooltip
{
get { return "Options"; }
}
/// <summary>
/// Menu shown when burger button is clicked.
/// </summary>
public System.Windows.Controls.ContextMenu BurgerButtonMenu
{
get { return FrameworkApplication.CreateContextMenu(_menuID); }
}
#endregion
}
/// <summary>
/// Button implementation to show the DockPane.
/// </summary>
internal class MainDockpane_ShowButton : Button
{
protected override void OnClick()
{
MainDockpaneViewModel.Show();
}
}
/// <summary>
/// Button implementation for the button on the menu of the burger button.
/// </summary>
}
Thanks in advance
Solved! Go to Solution.
I was missing iNotifyChangedEvent.Its Working
Thanks.