forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use HorizontalGrid and VerticalGrid string values to specify GridItem…
…sLayout in XAML (xamarin#8104) * Convert HorizontalGrid and VerticalGrid strings to ItemsLayout (xamarin#5577) * Support GridLayout in ItemsLayoutDesignTypeConverter xamarin#5577 * Add Issue5577 control to test ItemsLayoutConverter * Optimize ItemsLayoutTypeConverter * Expect InvalidOperationException, when span is missing in ItemsLayoutTypeConverter Co-authored-by: E.Z. Hart <[email protected]>
- Loading branch information
1 parent
3cf3286
commit f06cb1f
Showing
7 changed files
with
386 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5577.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,39 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<controls:TestContentPage | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:controls="clr-namespace:Xamarin.Forms.Controls" | ||
x:Class="Xamarin.Forms.Controls.Issues.Issue5577"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="*"/> | ||
</Grid.RowDefinitions> | ||
|
||
<Label Grid.Row="0" LineBreakMode="WordWrap" Text="Page should display 2 collection view with horizontal and vertical grid layouts"/> | ||
|
||
<CollectionView Grid.Row="1" ItemsSource="{Binding Animals}" ItemsLayout="HorizontalGrid, 2" BackgroundColor="Yellow"> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<StackLayout> | ||
<Label Text="{Binding Name}"/> | ||
<Label Text="{Binding Location}"/> | ||
</StackLayout> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
|
||
<CollectionView Grid.Row="2" ItemsSource="{Binding Animals}" ItemsLayout="VerticalGrid, 4"> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<StackLayout> | ||
<Label Text="{Binding Name}"/> | ||
<Label Text="{Binding Location}"/> | ||
</StackLayout> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
</Grid> | ||
</controls:TestContentPage> |
113 changes: 113 additions & 0 deletions
113
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5577.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,113 @@ | ||
using System.Collections.ObjectModel; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using Xamarin.Forms.Xaml; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[NUnit.Framework.Category(UITestCategories.CollectionView)] | ||
#endif | ||
#if APP | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 5577, "CollectionView XAML API suggestion", PlatformAffected.All)] | ||
public partial class Issue5577 : TestContentPage | ||
{ | ||
#if APP | ||
public Issue5577() | ||
{ | ||
InitializeComponent(); | ||
|
||
BindingContext = new ViewModel5577(); | ||
} | ||
#endif | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class ViewModel5577 | ||
{ | ||
public ViewModel5577() | ||
{ | ||
AddAnimals(); | ||
} | ||
|
||
public ObservableCollection<Model5577> Animals { get; private set; } = new ObservableCollection<Model5577>(); | ||
|
||
private void AddAnimals() | ||
{ | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Afghan Hound", | ||
Location = "Afghanistan", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Alpine Dachsbracke", | ||
Location = "Austria", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "American Bulldog", | ||
Location = "United States", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Bearded Collie", | ||
Location = "Scotland", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Boston Terrier", | ||
Location = "United States", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Canadian Eskimo", | ||
Location = "Canada", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Eurohound", | ||
Location = "Scandinavia", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Irish Terrier", | ||
Location = "Ireland", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Kerry Beagle", | ||
Location = "Ireland", | ||
}); | ||
Animals.Add(new Model5577 | ||
{ | ||
Name = "Norwegian Buhund", | ||
Location = "Norway", | ||
}); | ||
} | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class Model5577 | ||
{ | ||
public string Name { get; set; } | ||
public string Location { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return Name; | ||
} | ||
} | ||
} |
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
188 changes: 188 additions & 0 deletions
188
Xamarin.Forms.Core.UnitTests/ItemsLayoutTypeConverterTests.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,188 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Xamarin.Forms.Core.UnitTests | ||
{ | ||
[TestFixture] | ||
public class ItemsLayoutTypeConverterTests : BaseTestFixture | ||
{ | ||
[Test] | ||
public void HorizontalListShouldReturnLinearItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("HorizontalList"); | ||
Assert.AreSame(LinearItemsLayout.Horizontal, result); | ||
} | ||
|
||
[Test] | ||
public void VerticalListShouldReturnLinearItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("VerticalList"); | ||
Assert.AreSame(LinearItemsLayout.Vertical, result); | ||
} | ||
|
||
[Test] | ||
public void HorizontalGridShouldReturnGridItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("HorizontalGrid"); | ||
|
||
Assert.IsInstanceOf<GridItemsLayout>(result); | ||
var gridItemsLayout = (GridItemsLayout)result; | ||
Assert.AreEqual(ItemsLayoutOrientation.Horizontal, gridItemsLayout.Orientation); | ||
Assert.AreEqual(1, gridItemsLayout.Span); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridShouldReturnGridItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("VerticalGrid"); | ||
|
||
Assert.IsInstanceOf<GridItemsLayout>(result); | ||
var gridItemsLayout = (GridItemsLayout)result; | ||
Assert.AreEqual(ItemsLayoutOrientation.Vertical, gridItemsLayout.Orientation); | ||
Assert.AreEqual(1, gridItemsLayout.Span); | ||
} | ||
|
||
[Test] | ||
public void HorizontalGridWithSpan4ShouldReturnGridItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("HorizontalGrid, 4"); | ||
|
||
Assert.IsInstanceOf<GridItemsLayout>(result); | ||
var gridItemsLayout = (GridItemsLayout)result; | ||
Assert.AreEqual(ItemsLayoutOrientation.Horizontal, gridItemsLayout.Orientation); | ||
Assert.AreEqual(4, gridItemsLayout.Span); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridWithSpan2ShouldReturnGridItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("VerticalGrid,\t\t2"); | ||
|
||
Assert.IsInstanceOf<GridItemsLayout>(result); | ||
var gridItemsLayout = (GridItemsLayout)result; | ||
Assert.AreEqual(ItemsLayoutOrientation.Vertical, gridItemsLayout.Orientation); | ||
Assert.AreEqual(2, gridItemsLayout.Span); | ||
} | ||
|
||
[Test] | ||
public void HorizontalGridWithSpan987654ShouldReturnGridItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("HorizontalGrid,98654"); | ||
|
||
Assert.IsInstanceOf<GridItemsLayout>(result); | ||
var gridItemsLayout = (GridItemsLayout)result; | ||
Assert.AreEqual(ItemsLayoutOrientation.Horizontal, gridItemsLayout.Orientation); | ||
Assert.AreEqual(98654, gridItemsLayout.Span); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridWithSpan1234ShouldReturnGridItemsLayout() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
var result = converter.ConvertFromInvariantString("VerticalGrid, \t 1234"); | ||
|
||
Assert.IsInstanceOf<GridItemsLayout>(result); | ||
var gridItemsLayout = (GridItemsLayout)result; | ||
Assert.AreEqual(ItemsLayoutOrientation.Vertical, gridItemsLayout.Orientation); | ||
Assert.AreEqual(1234, gridItemsLayout.Span); | ||
} | ||
|
||
[Test] | ||
public void HorizontalGridWithSpan0ShouldShouldThrowArgumentException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<ArgumentException>(() => converter.ConvertFromInvariantString("HorizontalGrid, 0")); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridWithSpan0ShouldShouldThrowArgumentException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<ArgumentException>(() => converter.ConvertFromInvariantString("VerticalGrid, 0")); | ||
} | ||
|
||
[Test] | ||
public void HorizontalGridWithoutSpanShouldShouldThrowFormatException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("HorizontalGrid,")); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridWithoutSpanShouldShouldThrowFormatException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("VerticalGrid,")); | ||
} | ||
|
||
[Test] | ||
public void HorizontalGridWithSpanIsNotStringShouldShouldThrowFormatException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<FormatException>(() => converter.ConvertFromInvariantString("HorizontalGrid,test")); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridWithSpanIs1point5ShouldShouldThrowFormatException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<FormatException>(() => converter.ConvertFromInvariantString("VerticalGrid, 1.5")); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridWith2ArgumentsShouldShouldThrowFormatException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<FormatException>(() => converter.ConvertFromInvariantString("VerticalGrid, 2, 3")); | ||
} | ||
|
||
[Test] | ||
public void HorizontalGridWithSemicolonShouldShouldThrowInvalidOperationException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("HorizontalGrid; 2")); | ||
} | ||
|
||
[Test] | ||
public void LinearItemsLayoutShouldThrowInvalidOperationException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("LinearItemsLayout")); | ||
} | ||
|
||
[Test] | ||
public void HorizontalListWithArgumentShouldShouldThrowInvalidOperationException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("HorizontalList, 1")); | ||
} | ||
|
||
[Test] | ||
public void VerticalGridWithArgumentShouldShouldThrowInvalidOperationException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString("VerticalList, 2")); | ||
} | ||
|
||
[Test] | ||
public void EmptyStringShouldThrowInvalidOperationException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<InvalidOperationException>(() => converter.ConvertFromInvariantString(string.Empty)); | ||
} | ||
|
||
[Test] | ||
public void NullShouldThrowArgumentNullException() | ||
{ | ||
var converter = new ItemsLayoutTypeConverter(); | ||
Assert.Throws<ArgumentNullException>(() => converter.ConvertFromInvariantString(null)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.