Update MapOverlaysPanel.cs

This commit is contained in:
ClemensFischer 2025-01-26 21:12:34 +01:00
parent e8aec18323
commit 1f8164e82d

View file

@ -26,7 +26,7 @@ namespace MapControl
{ {
public static readonly DependencyProperty SourcePathsProperty = public static readonly DependencyProperty SourcePathsProperty =
DependencyPropertyHelper.Register<MapOverlaysPanel, IEnumerable<string>>(nameof(SourcePaths), null, DependencyPropertyHelper.Register<MapOverlaysPanel, IEnumerable<string>>(nameof(SourcePaths), null,
async (control, oldValue, newValue) => await control.SourcePathsPropertyChangedAsync(oldValue, newValue)); async (control, oldValue, newValue) => await control.SourcePathsPropertyChanged(oldValue, newValue));
public IEnumerable<string> SourcePaths public IEnumerable<string> SourcePaths
{ {
@ -34,7 +34,7 @@ namespace MapControl
set => SetValue(SourcePathsProperty, value); set => SetValue(SourcePathsProperty, value);
} }
private async Task SourcePathsPropertyChangedAsync(IEnumerable<string> oldSourcePaths, IEnumerable<string> newSourcePaths) private async Task SourcePathsPropertyChanged(IEnumerable<string> oldSourcePaths, IEnumerable<string> newSourcePaths)
{ {
Children.Clear(); Children.Clear();
@ -50,7 +50,7 @@ namespace MapControl
newCollection.CollectionChanged += SourcePathsCollectionChanged; newCollection.CollectionChanged += SourcePathsCollectionChanged;
} }
await AddOverlaysAsync(0, newSourcePaths); await AddOverlays(0, newSourcePaths);
} }
} }
@ -59,7 +59,7 @@ namespace MapControl
switch (args.Action) switch (args.Action)
{ {
case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Add:
await AddOverlaysAsync(args.NewStartingIndex, args.NewItems.Cast<string>()); await AddOverlays(args.NewStartingIndex, args.NewItems.Cast<string>());
break; break;
case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Remove:
@ -68,21 +68,21 @@ namespace MapControl
case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Move:
RemoveOverlays(args.OldStartingIndex, args.OldItems.Count); RemoveOverlays(args.OldStartingIndex, args.OldItems.Count);
await AddOverlaysAsync(args.NewStartingIndex, args.NewItems.Cast<string>()); await AddOverlays(args.NewStartingIndex, args.NewItems.Cast<string>());
break; break;
case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Replace:
await ReplaceOverlaysAsync(args.NewStartingIndex, args.NewItems.Cast<string>()); await ReplaceOverlays(args.NewStartingIndex, args.NewItems.Cast<string>());
break; break;
case NotifyCollectionChangedAction.Reset: case NotifyCollectionChangedAction.Reset:
Children.Clear(); Children.Clear();
await AddOverlaysAsync(0, SourcePaths); await AddOverlays(0, SourcePaths);
break; break;
} }
} }
private async Task AddOverlaysAsync(int index, IEnumerable<string> sourcePaths) private async Task AddOverlays(int index, IEnumerable<string> sourcePaths)
{ {
foreach (var sourcePath in sourcePaths) foreach (var sourcePath in sourcePaths)
{ {
@ -90,7 +90,7 @@ namespace MapControl
} }
} }
private async Task ReplaceOverlaysAsync(int index, IEnumerable<string> sourcePaths) private async Task ReplaceOverlays(int index, IEnumerable<string> sourcePaths)
{ {
foreach (var sourcePath in sourcePaths) foreach (var sourcePath in sourcePaths)
{ {