using System;
using System.Collections.ObjectModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using CommunityToolkit.WinUI;
using CommunityToolkit.WinUI.Controls;
namespace TestProject;
/// <summary>
/// 메인 페이지
/// </summary>
public sealed partial class MainPage : Page
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 난수기
/// </summary>
private static readonly Random _random = new Random();
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Instance
//////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 포토 항목 컬렉션
/// </summary>
public ObservableCollection<PhotoItem> PhotoItemCollection = [];
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
this.addItemButton.Click += addItemButton_Click;
this.addFixedItemButton.Click += addFixedItemButton_Click;
this.switchButton.Click += switchButton_Click;
this.listView.ItemClick += listView_ItemClick;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Add random sized image 버튼 클릭시 처리하기 - addItemButton_Click(sender, e)
/// <summary>
/// Add random sized image 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void addItemButton_Click(object sender, RoutedEventArgs e)
{
PhotoItemCollection.Add
(
new PhotoItem
{
Category = "Remove",
Thumbnail = "ms-appx:///Assets/BigFourSummerHeat.jpg",
Width = _random.Next(60, 180),
Height = _random.Next(40, 140)
}
);
}
#endregion
#region Add fixed sized image 버튼 클릭시 처리하기 - addFixedItemButton_Click(sender, e)
/// <summary>
/// Add fixed sized image 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void addFixedItemButton_Click(object sender, RoutedEventArgs e)
{
PhotoItemCollection.Add
(
new PhotoItem
{
Category = "Remove",
Thumbnail = "ms-appx:///Assets/BigFourSummerHeat.jpg",
Width = 150,
Height = 100
}
);
}
#endregion
#region Switch Orientation 버튼 클릭시 처리하기 - switchButton_Click(sender, e)
/// <summary>
/// Switch Orientation 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void switchButton_Click(object sender, RoutedEventArgs e)
{
if(this.listView.FindDescendant<WrapPanel>() is WrapPanel wrapPanel)
{
if(wrapPanel.Orientation == Orientation.Horizontal)
{
wrapPanel.Orientation = Orientation.Vertical;
ScrollViewer.SetVerticalScrollMode (this.listView, ScrollMode.Disabled);
ScrollViewer.SetHorizontalScrollMode(this.listView, ScrollMode.Auto );
ScrollViewer.SetVerticalScrollBarVisibility (this.listView, ScrollBarVisibility.Disabled);
ScrollViewer.SetHorizontalScrollBarVisibility(this.listView, ScrollBarVisibility.Auto );
}
else
{
wrapPanel.Orientation = Orientation.Horizontal;
ScrollViewer.SetVerticalScrollMode (this.listView, ScrollMode.Auto );
ScrollViewer.SetHorizontalScrollMode(this.listView, ScrollMode.Disabled);
ScrollViewer.SetVerticalScrollBarVisibility (this.listView, ScrollBarVisibility.Auto );
ScrollViewer.SetHorizontalScrollBarVisibility(this.listView, ScrollBarVisibility.Disabled);
}
}
}
#endregion
#region 리스트 뷰 항목 클릭시 처리하기 - listView_ItemClick(sender, e)
/// <summary>
/// 리스트 뷰 항목 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void listView_ItemClick(object sender, ItemClickEventArgs e)
{
PhotoItem item = e.ClickedItem as PhotoItem;
if(item == null)
{
return;
}
PhotoItemCollection.Remove(item);
}
#endregion
}