diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13232.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13232.xaml new file mode 100644 index 00000000000..bd14d231cd9 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13232.xaml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13232.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13232.xaml.cs new file mode 100644 index 00000000000..4402aace105 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13232.xaml.cs @@ -0,0 +1,88 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Input; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 13232, + "[Bug] Command is not working in SwipeItem", + PlatformAffected.Android | PlatformAffected.iOS)] + public partial class Issue13232 : TestContentPage + { + public Issue13232() + { +#if APP + InitializeComponent(); + BindingContext = new Issue13232ViewModel(); +#endif + } + + protected override void Init() + { + + } + } + + [Preserve(AllMembers = true)] + public class Issue13232Model + { + public int Id { get; set; } + public string Title { get; set; } + public string SubTitle { get; set; } + } + + [Preserve(AllMembers = true)] + public class Issue13232ViewModel : BindableObject + { + public Issue13232ViewModel() + { + Items = new ObservableCollection(); + + LoadItems(); + + DeleteCommand = new Command(async (object model) => + { + await Task.Delay(100); + + var issue13232Model = (Issue13232Model)model; + + var itemToDelete = Items.SingleOrDefault(t => t.Id == issue13232Model.Id); + + if (itemToDelete != null) + { + await Task.Delay(500); + + Items.Remove(itemToDelete); + } + }); + } + + public ObservableCollection Items { get; set; } + + public ICommand DeleteCommand { get; } + + void LoadItems() + { + for (int i = 0; i < 10; i++) + { + Items.Add(new Issue13232Model + { + Id = i + 1, + Title = $"Message {i + 1}", + SubTitle = $"Description {i + 1}", + }); + } + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 471fe5b59d4..a5ac9c69adb 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -1736,6 +1736,7 @@ + @@ -2148,6 +2149,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + MSBuild:UpdateDesignTimeXaml diff --git a/Xamarin.Forms.Core/SwipeView.cs b/Xamarin.Forms.Core/SwipeView.cs index a470e11db86..97780f128d8 100644 --- a/Xamarin.Forms.Core/SwipeView.cs +++ b/Xamarin.Forms.Core/SwipeView.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel; -using System.Runtime.CompilerServices; using Xamarin.Forms.Platform; namespace Xamarin.Forms @@ -117,6 +116,23 @@ protected override void OnBindingContextChanged() SetInheritedBindingContext(BottomItems, bc); } + protected override void OnParentSet() + { + base.OnParentSet(); + + if (LeftItems != null) + UpdateSwipeItemsParent(LeftItems); + + if (RightItems != null) + UpdateSwipeItemsParent(RightItems); + + if (TopItems != null) + UpdateSwipeItemsParent(TopItems); + + if (BottomItems != null) + UpdateSwipeItemsParent(BottomItems); + } + SwipeItems SwipeItemsDefaultValueCreator() => new SwipeItems(); static object SwipeItemsDefaultValueCreator(BindableObject bindable)