간단한
리스트뷰 데모코드입니다.
아이폰에서는 테이블뷰를 통해서 리스트를 출력하는 경우가 많은데 이런 경우 사용됩니다.
<?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:local="clr-namespace:DemoMyCollection" x:Class="DemoMyCollection.DemoMyCollectionPage"><ContentPage.Padding> <OnPlatform x:TypeArguments="Thickness" iOS="10, 20, 10, 0" Android="10, 0" WinPhone="10, 0" /> </ContentPage.Padding>
<ListView x:Name="listView" /> </ContentPage>
코드비하인드 클래스는 아래와 같습니다. using System;
using System.Collections.Generic;
namespace DemoMyCollection
{
public partial class DemoMyCollectionPage : ContentPage
{
public DemoMyCollectionPage()
{
InitializeComponent();
listView.ItemsSource = new List<Color>
{
Color.Aqua, Color.Black, Color.Blue, Color.Fuchsia,
Color.Gray, Color.Green, Color.Lime, Color.Maroon,
Color.Navy, Color.Olive, Color.Pink, Color.Purple,
Color.Red, Color.Silver, Color.Teal, Color.White, Color.Yellow
};
}
}
}
구분자를
보이지 않도록 변경할 경우
<ListView x:Name="listView"
SeparatorVisibility="None" />
SeparatorVisibility="None" />
다음과 같이 수정하면 구분자가 붉은 색으로 변경됩니다.
<ListView x:Name="listView"
SeparatorColor="Red" />
SeparatorColor="Red" />
선택된 아이템과 바인딩되는 데모는 다음과 같이 작성합니다.
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DemoMyCollection.ListViewArrayPage">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness"
iOS="10, 20, 10, 0"
Android="10,0"
WinPhone="10, 0" />
</ContentPage.Padding>
<StackLayout>
<ListView x:Name="listView"
SelectedItem="{Binding Source={x:Reference boxView},
Path=Color, Mode=TwoWay}">
<ListView.ItemsSource>
<x:Array Type="{x:Type Color}">
<x:Static Member="Color.Aqua" />
<x:Static Member="Color.Black" />
<x:Static Member="Color.Blue" />
<x:Static Member="Color.Fuchsia" />
<x:Static Member="Color.Gray" />
<x:Static Member="Color.Green" />
<x:Static Member="Color.Lime" />
<x:Static Member="Color.Maroon" />
<Color>Navy</Color>
<Color>Olive</Color>
<Color>Pink</Color>
<Color>Purple</Color>
<Color>Red</Color>
<Color>Silver</Color>
<Color>Teal</Color>
<Color>White</Color>
<Color>Yellow</Color>
</x:Array>
</ListView.ItemsSource>
</ListView>
<BoxView x:Name="boxView" Color="Lime" HeightRequest="100" />
</StackLayout>
</ContentPage>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DemoMyCollection.ListViewArrayPage">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness"
iOS="10, 20, 10, 0"
Android="10,0"
WinPhone="10, 0" />
</ContentPage.Padding>
<StackLayout>
<ListView x:Name="listView"
SelectedItem="{Binding Source={x:Reference boxView},
Path=Color, Mode=TwoWay}">
<ListView.ItemsSource>
<x:Array Type="{x:Type Color}">
<x:Static Member="Color.Aqua" />
<x:Static Member="Color.Black" />
<x:Static Member="Color.Blue" />
<x:Static Member="Color.Fuchsia" />
<x:Static Member="Color.Gray" />
<x:Static Member="Color.Green" />
<x:Static Member="Color.Lime" />
<x:Static Member="Color.Maroon" />
<Color>Navy</Color>
<Color>Olive</Color>
<Color>Pink</Color>
<Color>Purple</Color>
<Color>Red</Color>
<Color>Silver</Color>
<Color>Teal</Color>
<Color>White</Color>
<Color>Yellow</Color>
</x:Array>
</ListView.ItemsSource>
</ListView>
<BoxView x:Name="boxView" Color="Lime" HeightRequest="100" />
</StackLayout>
</ContentPage>
댓글 없음:
댓글 쓰기
참고: 블로그의 회원만 댓글을 작성할 수 있습니다.