■ FlipView 엘리먼트의 ItemTemplate 속성을 사용해 데이터를 바인딩하는 방법을 보여준다.
▶ ImageItem.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
namespace TestProject { /// <summary> /// 이미지 항목 /// </summary> public class ImageItem { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 이미지 경로 - ImagePath /// <summary> /// 이미지 경로 /// </summary> public string ImagePath { get; set; } #endregion } } |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?xml version="1.0" encoding="utf-8"?> <Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:TestProject" Title="TestProject"> <FlipView Width="400" Height="400" BorderThickness="1" BorderBrush="Black" ItemsSource="{x:Bind ImageItemList, Mode=OneWay}"> <FlipView.ItemTemplate> <DataTemplate x:DataType="local:ImageItem"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Image Grid.Row="0" VerticalAlignment="Center" Margin="10" Stretch="Uniform" Source="{x:Bind ImagePath}" /> <Border Grid.Row="1" Height="60" Background="#a5ffffff"> <TextBlock Name="Control2Text" Style="{StaticResource TitleTextBlockStyle}" HorizontalAlignment="Center" Padding="10 10" Foreground="Black" Text="{x:Bind Title}" /> </Border> </Grid> </DataTemplate> </FlipView.ItemTemplate> </FlipView> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using System.Collections.Generic; using Microsoft.UI.Xaml; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public sealed partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이미지 항목 리스트 - ImageItemList /// <summary> /// 이미지 항목 리스트 /// </summary> public List<ImageItem> ImageItemList { get; } = new List<ImageItem>() { new ImageItem { Title = "cliff" , ImagePath = "ms-appx:///IMAGE/cliff.jpg" }, new ImageItem { Title = "grapes" , ImagePath = "ms-appx:///IMAGE/grapes.jpg" }, new ImageItem { Title = "rainier", ImagePath = "ms-appx:///IMAGE/rainier.jpg" }, new ImageItem { Title = "sunset" , ImagePath = "ms-appx:///IMAGE/sunset.jpg" }, new ImageItem { Title = "valley" , ImagePath = "ms-appx:///IMAGE/valley.jpg" } }; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion } } |