This repository was archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Fix a bug where the collections MapElements cannot be manipulated fro… #113
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
47277c8
Fix a bug where the collections MapElements cannot be manipulated fro…
ocalvo 68093a9
Apply PR feedback
ocalvo f4f7116
Fix bug for Layers, and TitleSources
ocalvo 3cfc7d8
Fix the same bug for Layers, Routes and TitleSources properties.
ocalvo 5c89109
Apply PR feedback
ocalvo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
Microsoft.Toolkit.Win32.UI.Controls/Interop/WinRT/WindowsRuntimeCollection.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT | ||
| { | ||
| internal sealed class WindowsRuntimeCollection<T1, T2> : IList<T1> | ||
| { | ||
| private readonly IList<T2> collection; | ||
| private readonly Func<T2, T1> converter1; | ||
| private readonly Func<T1, T2> converter2; | ||
|
|
||
| public WindowsRuntimeCollection(IList<T2> collection, Func<T2, T1> converter1, Func<T1, T2> converter2) | ||
| { | ||
| this.collection = collection; | ||
| this.converter1 = converter1; | ||
| this.converter2 = converter2; | ||
| } | ||
|
|
||
| T1 IList<T1>.this[int index] | ||
| { | ||
| get => this.converter1(this.collection[index]); | ||
| set => this.collection[index] = this.converter2(value); | ||
| } | ||
|
|
||
| int ICollection<T1>.Count => this.collection.Count; | ||
|
ocalvo marked this conversation as resolved.
|
||
|
|
||
| bool ICollection<T1>.IsReadOnly => this.collection.IsReadOnly; | ||
|
|
||
| void ICollection<T1>.Add(T1 item) | ||
| { | ||
| this.collection.Add(this.converter2(item)); | ||
| } | ||
|
|
||
| void ICollection<T1>.Clear() | ||
| { | ||
| this.collection.Clear(); | ||
| } | ||
|
|
||
| bool ICollection<T1>.Contains(T1 item) | ||
| { | ||
| return this.collection.Contains(this.converter2(item)); | ||
| } | ||
|
|
||
| void ICollection<T1>.CopyTo(T1[] array, int arrayIndex) | ||
| { | ||
| this.collection.CopyTo(array.Select(e => this.converter2(e)).ToArray(), arrayIndex); | ||
| } | ||
|
|
||
| IEnumerator<T1> IEnumerable<T1>.GetEnumerator() | ||
| { | ||
| foreach (var e in this.collection) | ||
| { | ||
| yield return this.converter1(e); | ||
| } | ||
| } | ||
|
|
||
| IEnumerator IEnumerable.GetEnumerator() | ||
| { | ||
| foreach (var e in this.collection) | ||
| { | ||
| yield return this.converter1(e); | ||
| } | ||
| } | ||
|
|
||
| int IList<T1>.IndexOf(T1 item) | ||
| { | ||
| return this.collection.IndexOf(this.converter2(item)); | ||
| } | ||
|
|
||
| void IList<T1>.Insert(int index, T1 item) | ||
| { | ||
| this.collection.Insert(index, this.converter2(item)); | ||
| } | ||
|
|
||
| bool ICollection<T1>.Remove(T1 item) | ||
| { | ||
| return this.collection.Remove(this.converter2(item)); | ||
| } | ||
|
|
||
| void IList<T1>.RemoveAt(int index) | ||
| { | ||
| this.collection.RemoveAt(index); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,10 +77,7 @@ protected override void OnInitialized(EventArgs e) | |
| Bind(nameof(ZoomLevel), ZoomLevelProperty, windows.UI.Xaml.Controls.Maps.MapControl.ZoomLevelProperty); | ||
| Bind(nameof(Center), CenterProperty, windows.UI.Xaml.Controls.Maps.MapControl.CenterProperty, new WindowsXamlHostWrapperConverter()); | ||
| Bind(nameof(LoadingStatus), LoadingStatusProperty, windows.UI.Xaml.Controls.Maps.MapControl.LoadingStatusProperty, new WindowsXamlHostWrapperConverter()); | ||
| Bind(nameof(MapElements), MapElementsProperty, windows.UI.Xaml.Controls.Maps.MapControl.MapElementsProperty); | ||
|
ocalvo marked this conversation as resolved.
|
||
| Bind(nameof(Pitch), PitchProperty, windows.UI.Xaml.Controls.Maps.MapControl.PitchProperty); | ||
| Bind(nameof(Routes), RoutesProperty, windows.UI.Xaml.Controls.Maps.MapControl.RoutesProperty); | ||
| Bind(nameof(TileSources), TileSourcesProperty, windows.UI.Xaml.Controls.Maps.MapControl.TileSourcesProperty); | ||
| Bind(nameof(ZoomInteractionMode), ZoomInteractionModeProperty, windows.UI.Xaml.Controls.Maps.MapControl.ZoomInteractionModeProperty, new WindowsXamlHostWrapperConverter()); | ||
| Bind(nameof(TransitFeaturesVisible), TransitFeaturesVisibleProperty, windows.UI.Xaml.Controls.Maps.MapControl.TransitFeaturesVisibleProperty); | ||
| Bind(nameof(TiltInteractionMode), TiltInteractionModeProperty, windows.UI.Xaml.Controls.Maps.MapControl.TiltInteractionModeProperty, new WindowsXamlHostWrapperConverter()); | ||
|
|
@@ -95,7 +92,6 @@ protected override void OnInitialized(EventArgs e) | |
| /* Bind(nameof(ViewPadding), ViewPaddingProperty, windows.UI.Xaml.Controls.Maps.MapControl.ViewPaddingProperty); | ||
| Bind(nameof(StyleSheet), StyleSheetProperty, windows.UI.Xaml.Controls.Maps.MapControl.StyleSheetProperty, new WindowsXamlHostWrapperConverter()); */ | ||
| Bind(nameof(MapProjection), MapProjectionProperty, windows.UI.Xaml.Controls.Maps.MapControl.MapProjectionProperty, new WindowsXamlHostWrapperConverter()); | ||
| Bind(nameof(Layers), LayersProperty, windows.UI.Xaml.Controls.Maps.MapControl.LayersProperty); | ||
| Bind(nameof(Region), RegionProperty, windows.UI.Xaml.Controls.Maps.MapControl.RegionProperty); | ||
|
|
||
| Children.OfType<WindowsXamlHostBase>().ToList().ForEach(RelocateChildToUwpControl); | ||
|
|
@@ -156,11 +152,6 @@ private void RelocateChildToUwpControl(WindowsXamlHostBase obj) | |
| public static DependencyProperty LocationProperty { get; } = DependencyProperty.Register(nameof(Center), typeof(Geopoint), typeof(MapControl)); | ||
| */ | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.MapElementsProperty"/> | ||
| /// </summary> | ||
| public static DependencyProperty MapElementsProperty { get; } = DependencyProperty.Register(nameof(MapElements), typeof(System.Collections.Generic.IList<MapElement>), typeof(MapControl)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding the removal of Dependency Properties, I assume that means data binding on those will be not possible. Am I missing something? |
||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.MapServiceTokenProperty"/> | ||
| /// </summary> | ||
|
|
@@ -183,21 +174,11 @@ private void RelocateChildToUwpControl(WindowsXamlHostBase obj) | |
| /// </summary> | ||
| public static DependencyProperty PitchProperty { get; } = DependencyProperty.Register(nameof(Pitch), typeof(double), typeof(MapControl)); | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.RoutesProperty"/> | ||
| /// </summary> | ||
| public static DependencyProperty RoutesProperty { get; } = DependencyProperty.Register(nameof(Routes), typeof(System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapRouteView>), typeof(MapControl)); | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.StyleProperty"/> | ||
| /// </summary> | ||
| public static new DependencyProperty StyleProperty { get; } = DependencyProperty.Register(nameof(Style), typeof(MapStyle), typeof(MapControl)); | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.TileSourcesProperty"/> | ||
| /// </summary> | ||
| public static DependencyProperty TileSourcesProperty { get; } = DependencyProperty.Register(nameof(TileSources), typeof(System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapTileSource>), typeof(MapControl)); | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.TrafficFlowVisibleProperty"/> | ||
| /// </summary> | ||
|
|
@@ -300,11 +281,6 @@ private void RelocateChildToUwpControl(WindowsXamlHostBase obj) | |
| public static DependencyProperty ViewPaddingProperty { get; } = DependencyProperty.Register(nameof(ViewPadding), typeof(windows.UI.Xaml.Thickness), typeof(MapControl)); | ||
| */ | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.LayersProperty"/> | ||
| /// </summary> | ||
| public static DependencyProperty LayersProperty { get; } = DependencyProperty.Register(nameof(Layers), typeof(System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer>), typeof(MapControl)); | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.RegionProperty"/> | ||
| /// </summary> | ||
|
|
@@ -618,12 +594,25 @@ public MapLoadingStatus LoadingStatus | |
| get => (MapLoadingStatus)GetValue(LoadingStatusProperty); | ||
| } | ||
|
|
||
| private System.Collections.Generic.IList<MapElement> _mapElements; | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.MapElements"/> | ||
| /// </summary> | ||
| public System.Collections.Generic.IList<MapElement> MapElements | ||
| { | ||
| get => (System.Collections.Generic.IList<MapElement>)GetValue(MapElementsProperty); | ||
| get | ||
| { | ||
| if (_mapElements == null) | ||
| { | ||
| _mapElements = new WindowsRuntimeCollection<MapElement, windows.UI.Xaml.Controls.Maps.MapElement>( | ||
| this.UwpControl.MapElements, | ||
| mp => MapElement.FromMapElement(mp), | ||
| mp => mp.UwpInstance); | ||
| } | ||
|
|
||
| return _mapElements; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -655,15 +644,15 @@ public double Pitch | |
| /// </summary> | ||
| public System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapRouteView> Routes | ||
| { | ||
| get => (System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapRouteView>)GetValue(RoutesProperty); | ||
| get => this.UwpControl.Routes; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets <see cref="windows.UI.Xaml.Controls.Maps.MapControl.TileSources"/> | ||
| /// </summary> | ||
| public System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapTileSource> TileSources | ||
| { | ||
| get => (System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapTileSource>)GetValue(TileSourcesProperty); | ||
| get => this.UwpControl.TileSources; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -822,8 +811,8 @@ public MapProjection MapProjection | |
| /// </summary> | ||
| public System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer> Layers | ||
| { | ||
| get => (System.Collections.Generic.IList<windows.UI.Xaml.Controls.Maps.MapLayer>)GetValue(LayersProperty); | ||
| set => SetValue(LayersProperty, value); | ||
| get => this.UwpControl.Layers; | ||
| set => this.UwpControl.Layers = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.