Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -r8b3f995635bbd317936d1607058bb0e80c3c5508 -r05b272ce1fe41ddbb79d367399d1339caec1a06b --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 8b3f995635bbd317936d1607058bb0e80c3c5508) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 05b272ce1fe41ddbb79d367399d1339caec1a06b) @@ -38,6 +38,8 @@ public sealed partial class MapLegendView : UserControl, ISelectionProvider { private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; + + private bool settingData; private IMapControl mapControl; public event EventHandler SelectionChanged; @@ -89,7 +91,11 @@ } set { + settingData = true; + treeViewControl.Data = (MapData) value; + + settingData = false; } } @@ -103,7 +109,10 @@ private void TreeViewControlSelectedDataChanged(object sender, EventArgs e) { - SelectionChanged?.Invoke(this, new EventArgs()); + if (SelectionChanged != null && !settingData) + { + SelectionChanged(this, new EventArgs()); + } } private void RegisterTreeNodeInfos() Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -r05b272ce1fe41ddbb79d367399d1339caec1a06b --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 05b272ce1fe41ddbb79d367399d1339caec1a06b) @@ -268,9 +268,9 @@ [Test] [Apartment(ApartmentState.STA)] - public void TreeViewSelectedNodeChanged_Always_SelectionChangedFired() + public void GivenMapLegendView_WhenSelectedNodeChanged_SelectionChangedFired() { - // Setup + // Given var mapData = new MapLineData("line data"); var mapDataCollection = new MapDataCollection("collection"); @@ -282,21 +282,42 @@ }) { var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); - WindowsFormsTestHelper.Show(treeViewControl); var selectionChangedCount = 0; view.SelectionChanged += (sender, args) => selectionChangedCount++; - // Call + // When treeViewControl.TrySelectNodeForData(mapData); - // Assert + // Then Assert.AreEqual(1, selectionChangedCount); } WindowsFormsTestHelper.CloseAll(); } + [Test] + [Apartment(ApartmentState.STA)] + public void GivenMapLegendView_WhenSettingData_SelectionChangedNotFired() + { + // Given + using (var view = new MapLegendView(contextMenuBuilderProvider)) + { + var selectionChangedCount = 0; + view.SelectionChanged += (sender, args) => selectionChangedCount++; + + var treeViewControl = TypeUtils.GetField(view, "treeViewControl"); + WindowsFormsTestHelper.Show(treeViewControl); + + // When + view.Data = new MapDataCollection("collection"); + + // Then + Assert.AreEqual(0, selectionChangedCount); + } + WindowsFormsTestHelper.CloseAll(); + } + private static MapFeature[] CreateFeatures() { return new[]