This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix exception deleting items from BindableLayout using SwipeView (#14068
- Loading branch information
1 parent
3703741
commit ba7bdcd
Showing
4 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue14066.xaml
This file contains 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,61 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<local:TestContentPage | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
xmlns:local="using:Xamarin.Forms.Controls" | ||
x:Class="Xamarin.Forms.Controls.Issues.Issue14066" | ||
Title="Issue 14066"> | ||
<StackLayout> | ||
<Label | ||
Padding="12" | ||
BackgroundColor="Black" | ||
TextColor="White" | ||
Text="Swipe any SwipeView, without exceptions, the test has passed." /> | ||
<StackLayout | ||
Margin="30" | ||
Orientation="Vertical"> | ||
<Button | ||
Text="Add Items to the List" | ||
Command="{Binding AddCommand}" | ||
TextColor="White" | ||
BackgroundColor="Black" /> | ||
<StackLayout | ||
x:Name="MyList" | ||
BindableLayout.ItemsSource="{Binding CollectionsList}"> | ||
<BindableLayout.ItemTemplate> | ||
<DataTemplate> | ||
<SwipeView> | ||
<Grid | ||
HeightRequest="40" | ||
BackgroundColor="White" | ||
Margin="10"> | ||
<Label | ||
VerticalOptions="CenterAndExpand" | ||
Text="{Binding Name}" /> | ||
</Grid> | ||
<SwipeView.LeftItems> | ||
<SwipeItems Mode="Execute"> | ||
<SwipeItemView | ||
BackgroundColor="Red" | ||
Command="{Binding Path=BindingContext.DeleteCommand, Source={x:Reference MyList}}" | ||
CommandParameter="{Binding .}" /> | ||
</SwipeItems> | ||
</SwipeView.LeftItems> | ||
<SwipeView.RightItems> | ||
<SwipeItems Mode="Execute"> | ||
<SwipeItemView | ||
BackgroundColor="Red" | ||
Command="{Binding Path=BindingContext.DeleteCommand, Source={x:Reference MyList}}" | ||
CommandParameter="{Binding .}" /> | ||
</SwipeItems> | ||
</SwipeView.RightItems> | ||
</SwipeView> | ||
</DataTemplate> | ||
</BindableLayout.ItemTemplate> | ||
</StackLayout> | ||
</StackLayout> | ||
</StackLayout> | ||
</local:TestContentPage> |
89 changes: 89 additions & 0 deletions
89
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue14066.xaml.cs
This file contains 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,89 @@ | ||
using System.Collections.Generic; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using System.Collections.ObjectModel; | ||
using System.Windows.Input; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 14066, "[Bug] Deleting items with SwipeView in StackLayout", | ||
PlatformAffected.Android)] | ||
public partial class Issue14066 : TestContentPage | ||
{ | ||
public Issue14066() | ||
{ | ||
#if APP | ||
InitializeComponent(); | ||
BindingContext = new Issue14066ViewModel(); | ||
#endif | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class Issue14066Model | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
public class Issue14066ViewModel : BindableObject | ||
{ | ||
ObservableCollection<Issue14066Model> _collectionsList; | ||
|
||
public ObservableCollection<Issue14066Model> CollectionsList | ||
{ | ||
get { return _collectionsList; } | ||
set | ||
{ | ||
_collectionsList = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public ICommand DeleteCommand { get; } | ||
|
||
public ICommand AddCommand { get; } | ||
|
||
|
||
public Issue14066ViewModel() | ||
{ | ||
CollectionsList = new ObservableCollection<Issue14066Model>() | ||
{ | ||
new Issue14066Model { Name= "Item 1" }, | ||
new Issue14066Model { Name= "Item 2" }, | ||
new Issue14066Model { Name= "Item 3" }, | ||
new Issue14066Model { Name= "Item 4" }, | ||
}; | ||
|
||
DeleteCommand = new Command(OnDeleteTapped); | ||
|
||
AddCommand = new Command(AddItmes); | ||
} | ||
|
||
void AddItmes(object obj) | ||
{ | ||
Issue14066Model offersModel = new Issue14066Model | ||
{ | ||
Name = "New Item Added" | ||
}; | ||
|
||
CollectionsList.Add(offersModel); | ||
} | ||
|
||
void OnDeleteTapped(object obj) | ||
{ | ||
var content = obj as Issue14066Model; | ||
CollectionsList.Remove(content); | ||
} | ||
} | ||
} |
This file contains 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 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