Skip to content

Commit

Permalink
🚀 [Code] Updated FavoritePage.xaml, adding dynamic columns in Collect…
Browse files Browse the repository at this point in the history
…ionView based on device width
  • Loading branch information
danielmonettelli committed Apr 19, 2024
1 parent 0b4af60 commit c6815f9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Meow/ViewModels/FavoriteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public partial class FavoriteViewModel : BaseViewModel
[ObservableProperty]
private FavoriteCatResponse selectedFavoriteCat = new();

[ObservableProperty]
private int columns;

private readonly ICatService _catService;

public FavoriteViewModel(ICatService catService)
Expand Down
5 changes: 3 additions & 2 deletions Meow/Views/FavoritePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
xmlns:reusablecomponent="clr-namespace:Meow.ReusableComponents"
xmlns:viewModel="clr-namespace:Meow.ViewModels"
ios:Page.UseSafeArea="true"
x:DataType="viewModel:FavoriteViewModel">
x:DataType="viewModel:FavoriteViewModel"
SizeChanged="ContentPage_SizeChanged">

<ContentPage.Resources>
<Style TargetType="Border">
Expand Down Expand Up @@ -49,7 +50,7 @@
<GridItemsLayout
HorizontalItemSpacing="16"
Orientation="Vertical"
Span="2"
Span="{Binding Columns}"
VerticalItemSpacing="16" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
Expand Down
5 changes: 5 additions & 0 deletions Meow/Views/FavoritePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ protected async override void OnAppearing()

await vm.InitializeDataAsync();
}

private void ContentPage_SizeChanged(object sender, EventArgs e)
{
vm.Columns = (int)(Width / 168);
}
}

0 comments on commit c6815f9

Please sign in to comment.