toy mart using listview - 2/5

main
syneffort 2 years ago
parent 880ce862be
commit ae58254191
  1. 4
      XamarinStudy/XamarinStudy/XamarinStudy/App.xaml.cs
  2. 21
      XamarinStudy/XamarinStudy/XamarinStudy/Commons/ValueConverter.cs
  3. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Block1.png
  4. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Block2.png
  5. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Block3.png
  6. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Car1.png
  7. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Car2.png
  8. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Car3.png
  9. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Figure1.png
  10. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Figure2.png
  11. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Figure3.png
  12. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Plane1.png
  13. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Plane2.png
  14. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Plane3.png
  15. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Robot1.png
  16. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Robot2.png
  17. BIN
      XamarinStudy/XamarinStudy/XamarinStudy/Imgs/Robot3.png
  18. 64
      XamarinStudy/XamarinStudy/XamarinStudy/Models/Toy.cs
  19. 39
      XamarinStudy/XamarinStudy/XamarinStudy/Views/ToyMartPage.xaml
  20. 29
      XamarinStudy/XamarinStudy/XamarinStudy/Views/ToyMartPage.xaml.cs
  21. 39
      XamarinStudy/XamarinStudy/XamarinStudy/XamarinStudy.csproj

@ -55,7 +55,9 @@ namespace XamarinStudy
//MainPage = new NavigationPage(new SampleTableViewSimpleRegisterPage());
MainPage = new SampleListViewPage();
//MainPage = new SampleListViewPage();
MainPage = new ToyMartPage();
}
protected override void OnStart()

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Xamarin.Forms;
namespace XamarinStudy.Commons
{
internal class ValueConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ImageSource.FromResource(string.Format("XamarinStudy.Imgs.{0}", value ?? ""));
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XamarinStudy.Models
{
internal class Toy
{
public enum TOY_CATEGORY { Robot, Car, Plane, Figure, Block }
public string Name { get; set; }
public int Price { get; set; }
public int Count { get; set; }
public string Image { get => $"{this.Name}.png"; }
public bool Checked { get; set; }
public TOY_CATEGORY Category { get; set; }
}
class KindOf<K, T> : List<T>
{
public K Title { get; set; }
public KindOf(K title, IEnumerable<T> list)
{
this.Title = title;
this.AddRange(list);
}
}
internal class ToyRepository
{
public static List<Toy> ToyList { get; private set; }
public static List<KindOf<string, Toy>>ToyListKindOf { get; set; }
static ToyRepository()
{
ToyList = new List<Toy>()
{
new Toy() {Name = "Robot1", Price = 10000, Category = Toy.TOY_CATEGORY.Robot },
new Toy() {Name = "Robot2", Price = 80000, Category = Toy.TOY_CATEGORY.Robot },
new Toy() {Name = "Robot3", Price = 90000, Category = Toy.TOY_CATEGORY.Robot },
new Toy() {Name = "Car1", Price = 1000, Category = Toy.TOY_CATEGORY.Car },
new Toy() {Name = "Car2", Price = 60000, Category = Toy.TOY_CATEGORY.Car },
new Toy() {Name = "Car3", Price = 70000, Category = Toy.TOY_CATEGORY.Car },
new Toy() {Name = "Plane1", Price = 120000, Category = Toy.TOY_CATEGORY.Plane },
new Toy() {Name = "Plane2", Price = 60000, Category = Toy.TOY_CATEGORY.Plane },
new Toy() {Name = "Plane3", Price = 50000, Category = Toy.TOY_CATEGORY.Plane },
new Toy() {Name = "Figure1", Price = 120000, Category = Toy.TOY_CATEGORY.Figure },
new Toy() {Name = "Figure2", Price = 60000, Category = Toy.TOY_CATEGORY.Figure },
new Toy() {Name = "Figure3", Price = 50000, Category = Toy.TOY_CATEGORY.Figure },
new Toy() {Name = "Block1", Price = 20000, Category = Toy.TOY_CATEGORY.Block },
new Toy() {Name = "Block2", Price = 25000, Category = Toy.TOY_CATEGORY.Block },
new Toy() {Name = "Block3", Price = 32000, Category = Toy.TOY_CATEGORY.Block },
};
// Category로 그룹화, 그룹 내 Key = Category,
ToyListKindOf = ToyList.GroupBy(t => t.Category.ToString()).Select(g => new KindOf<string, Toy>(g.Key, g)).ToList();
}
}
}

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:common="clr-namespace:XamarinStudy.Commons;assembly=XamarinStudy"
x:Class="XamarinStudy.Views.ToyMartPage">
<ContentPage.Resources>
<ResourceDictionary>
<common:ValueConverter x:Key="cvt"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<ListView x:Name="menuListView" ItemsSource="{Binding .}" HasUnevenRows="True" IsGroupingEnabled="True" GroupDisplayBinding="{Binding Title}">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" BackgroundColor="DarkSlateBlue" Padding="2 10">
<Label Text="{Binding Title}" FontSize="Large" TextColor="White"/>
<Label Text=": " FontSize="Large" TextColor="White"/>
<Label Text="{Binding Count}" FontSize="Large" TextColor="White"/>
<Label Text="ea" FontSize="Large" TextColor="White"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="6, 6">
<Image Source="{Binding Image, Converter={StaticResource cvt}}" WidthRequest="50" HeightRequest="50"/>
<Label Text="{Binding Name}" FontSize="Large" VerticalTextAlignment="Center" HorizontalOptions="FillAndExpand"/>
<Label Text="{Binding Price}" FontSize="Medium" VerticalTextAlignment="Center" HorizontalOptions="FillAndExpand"/>
<CheckBox IsChecked="{Binding Checked}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using XamarinStudy.Models;
namespace XamarinStudy.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ToyMartPage : ContentPage
{
public ToyMartPage()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
ToyRepository dd = new ToyRepository();
//menuListView.ItemsSource = ToyRepository.ToyList;
menuListView.ItemsSource = ToyRepository.ToyListKindOf;
}
}
}

@ -5,6 +5,42 @@
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<ItemGroup>
<None Remove="Imgs\Block1.png" />
<None Remove="Imgs\Block2.png" />
<None Remove="Imgs\Block3.png" />
<None Remove="Imgs\Car1.png" />
<None Remove="Imgs\Car2.png" />
<None Remove="Imgs\Car3.png" />
<None Remove="Imgs\Figure1.png" />
<None Remove="Imgs\Figure2.png" />
<None Remove="Imgs\Figure3.png" />
<None Remove="Imgs\Plane1.png" />
<None Remove="Imgs\Plane2.png" />
<None Remove="Imgs\Plane3.png" />
<None Remove="Imgs\Robot1.png" />
<None Remove="Imgs\Robot2.png" />
<None Remove="Imgs\Robot3.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Imgs\Block1.png" />
<EmbeddedResource Include="Imgs\Block2.png" />
<EmbeddedResource Include="Imgs\Block3.png" />
<EmbeddedResource Include="Imgs\Car1.png" />
<EmbeddedResource Include="Imgs\Car2.png" />
<EmbeddedResource Include="Imgs\Car3.png" />
<EmbeddedResource Include="Imgs\Figure1.png" />
<EmbeddedResource Include="Imgs\Figure2.png" />
<EmbeddedResource Include="Imgs\Figure3.png" />
<EmbeddedResource Include="Imgs\Plane1.png" />
<EmbeddedResource Include="Imgs\Plane2.png" />
<EmbeddedResource Include="Imgs\Plane3.png" />
<EmbeddedResource Include="Imgs\Robot1.png" />
<EmbeddedResource Include="Imgs\Robot2.png" />
<EmbeddedResource Include="Imgs\Robot3.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2196" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
@ -74,5 +110,8 @@
<EmbeddedResource Update="Views\SampleToolbarPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\ToyMartPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
Loading…
Cancel
Save