[C#/WINUI3/.NET8] WebView2 클래스 : 웹 페이지의 HTML을 클립보드 복사하기
■ WebView2 클래스에서 웹 페이지의 HTML을 클립보드에 복사하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를
■ WebView2 클래스에서 웹 페이지의 HTML을 클립보드에 복사하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를
■ WebView2 클래스에서 웹 페이지에서 HTML 본문의 텍스트를 클립보드에 복사하드는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서
■ 메인 크롬 브라우저 활성 탭에서 URL을 구하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를
■ 메인 크롬 브라우저 활성 탭에서 URL을 구하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를
■ FlaUI.UIA3 누겟을 설치하는 방법을 보여준다. 1. Visual Studio를 실행한다. 2. [도구] / [NuGet 패키지 관리자] / [패키지 관리자 콘솔] 메뉴를 실행한다.
■ RefreshContainer 클래스의 RefreshRequested 이벤트/RequestRefresh 메소드를 사용해 목록을 갱신하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType
■ SwipeControl 엘리먼트의 LeftItems 속성을 사용해 스와이프 항목을 표시하는 방법을 보여준다. ▶ 예제 코드 (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 |
<?xml version="1.0" encoding="utf-8"?> <Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <SwipeControl HorizontalAlignment="Center" VerticalAlignment="Center"> <SwipeControl.LeftItems> <SwipeItems> <SwipeItem Text="Pin"> <SwipeItem.IconSource> <SymbolIconSource Symbol="Pin" /> </SwipeItem.IconSource> </SwipeItem> </SwipeItems> </SwipeControl.LeftItems> <Border Width="180" Height="44" BorderThickness="1" BorderBrush="Black"> <TextBlock Margin="5 10 0 0" Text="Swipe to Pin" /> </Border> </SwipeControl> </Page> |
■ ListView 엘리먼트의 ItemTemplate 속성에서 SwipeControl 엘리먼트를 사용해 항목별 살짝 밀기 명령을 만드는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※
■ UserControl 엘리먼트의 ContextFlyout 속성에서 MenuFlyout 객체를 사용해 명령을 실행하는 방법을 보여준다. ▶ FavoriteCommand.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 49 50 51 52 53 54 55 |
using System; using System.Windows.Input; namespace TestProject; /// <summary> /// 즐겨찾기 명령 /// </summary> public class FavoriteCommand: ICommand { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 변경시 - CanExecuteChanged /// <summary> /// 실행 가능 여부 변경시 /// </summary> public event EventHandler CanExecuteChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 구하기 - CanExecute(parameter) /// <summary> /// 실행 가능 여부 구하기 /// </summary> /// <param name="parameter">매개 변수</param> /// <returns>실행 가능 여부</returns> public bool CanExecute(object parameter) { return true; } #endregion #region 실행하기 - Execute(parameter) /// <summary> /// 실행하기 /// </summary> /// <param name="parameter">매개 변수</param> public void Execute(object parameter) { Podcast podcast = parameter as Podcast; podcast.IsFavorite = !podcast.IsFavorite; } #endregion } |
▶ Podcast.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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
using System.ComponentModel; namespace TestProject; /// <summary> /// 팟캐스트 /// </summary> public class Podcast : INotifyPropertyChanged { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 속성 변경시 - PropertyChanged /// <summary> /// 속성 변경시 /// </summary> public event PropertyChangedEventHandler PropertyChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 즐겨찾기 여부 /// </summary> private bool isFavorite = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 설명 - Description /// <summary> /// 설명 /// </summary> public string Description { get; set; } #endregion #region 즐겨찾기 여부 - IsFavorite /// <summary> /// 즐겨찾기 여부 /// </summary> public bool IsFavorite { get { return this.isFavorite; } set { this.isFavorite = value; FirePropertyChangedEvent("IsFavorite"); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName) /// <summary> /// 속성 변경시 이벤트 발생시키기 /// </summary> /// <param name="propertyName">속성명</param> private void FirePropertyChangedEvent(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion } |
▶ PodcastControl.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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<UserControl x:Class="TestProject.PodcastControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" IsTabStop="True" UseSystemFocusVisuals="True"> <UserControl.Resources> <SymbolIconSource x:Key="FavoriteSymbolIconSourceKey" Symbol="Favorite" /> <SwipeItems x:Key="RightSwipeItemsKey" Mode="Reveal"> <SwipeItem Background="Yellow" IconSource="{StaticResource FavoriteSymbolIconSourceKey}" Text="Favorite" Invoked="swipeItem_Invoked" /> </SwipeItems> </UserControl.Resources> <UserControl.ContextFlyout> <MenuFlyout> <MenuFlyoutItem Text="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </MenuFlyout> </UserControl.ContextFlyout> <SwipeControl RightItems="{StaticResource RightSwipeItemsKey}"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="HoveringStates"> <VisualState x:Name="HoverButtonsShown"> <VisualState.Setters> <Setter Target="hoverAreaGrid.Visibility" Value="Visible" /> </VisualState.Setters> </VisualState> <VisualState x:Name="HoverButtonsHidden" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid Margin="10 0 10 0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0" Margin="5" Spacing="10"> <TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="{x:Bind Podcast.Title, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.Description, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.IsFavorite, Mode=OneWay}" /> </StackPanel> <Grid Name="hoverAreaGrid" Grid.Column="1" VerticalAlignment="Stretch" Visibility="Collapsed"> <AppBarButton VerticalAlignment="Center" IsTabStop="False" Icon="OutlineStar" Label="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </Grid> </Grid> </SwipeControl> </UserControl> |
▶
■ SwipeControl 엘리먼트의 RightItems 속성을 사용해 스와이프 항목을 표시하는 방법을 보여준다. ▶ FavoriteCommand.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 49 50 51 52 53 54 55 |
using System; using System.Windows.Input; namespace TestProject; /// <summary> /// 즐겨찾기 명령 /// </summary> public class FavoriteCommand: ICommand { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 변경시 - CanExecuteChanged /// <summary> /// 실행 가능 여부 변경시 /// </summary> public event EventHandler CanExecuteChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 구하기 - CanExecute(parameter) /// <summary> /// 실행 가능 여부 구하기 /// </summary> /// <param name="parameter">매개 변수</param> /// <returns>실행 가능 여부</returns> public bool CanExecute(object parameter) { return true; } #endregion #region 실행하기 - Execute(parameter) /// <summary> /// 실행하기 /// </summary> /// <param name="parameter">매개 변수</param> public void Execute(object parameter) { Podcast podcast = parameter as Podcast; podcast.IsFavorite = !podcast.IsFavorite; } #endregion } |
▶ Podcast.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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
using System.ComponentModel; namespace TestProject; /// <summary> /// 팟캐스트 /// </summary> public class Podcast : INotifyPropertyChanged { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 속성 변경시 - PropertyChanged /// <summary> /// 속성 변경시 /// </summary> public event PropertyChangedEventHandler PropertyChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 즐겨찾기 여부 /// </summary> private bool isFavorite = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 설명 - Description /// <summary> /// 설명 /// </summary> public string Description { get; set; } #endregion #region 즐겨찾기 여부 - IsFavorite /// <summary> /// 즐겨찾기 여부 /// </summary> public bool IsFavorite { get { return this.isFavorite; } set { this.isFavorite = value; FirePropertyChangedEvent("IsFavorite"); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName) /// <summary> /// 속성 변경시 이벤트 발생시키기 /// </summary> /// <param name="propertyName">속성명</param> private void FirePropertyChangedEvent(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion } |
▶ PodcastControl.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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<UserControl x:Class="TestProject.PodcastControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" IsTabStop="True" UseSystemFocusVisuals="True"> <UserControl.Resources> <SymbolIconSource x:Key="FavoriteSymbolIconSourceKey" Symbol="Favorite" /> <SwipeItems x:Key="RightSwipeItemsKey" Mode="Reveal"> <SwipeItem Background="Yellow" IconSource="{StaticResource FavoriteSymbolIconSourceKey}" Text="Favorite" Invoked="swipeItem_Invoked" /> </SwipeItems> </UserControl.Resources> <UserControl.ContextFlyout> <MenuFlyout> <MenuFlyoutItem Text="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </MenuFlyout> </UserControl.ContextFlyout> <SwipeControl RightItems="{StaticResource RightSwipeItemsKey}"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="HoveringStates"> <VisualState x:Name="HoverButtonsShown"> <VisualState.Setters> <Setter Target="hoverAreaGrid.Visibility" Value="Visible" /> </VisualState.Setters> </VisualState> <VisualState x:Name="HoverButtonsHidden" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid Margin="10 0 10 0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0" Margin="5" Spacing="10"> <TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="{x:Bind Podcast.Title, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.Description, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.IsFavorite, Mode=OneWay}" /> </StackPanel> <Grid Name="hoverAreaGrid" Grid.Column="1" VerticalAlignment="Stretch" Visibility="Collapsed"> <AppBarButton VerticalAlignment="Center" IsTabStop="False" Icon="OutlineStar" Label="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </Grid> </Grid> </SwipeControl> </UserControl> |
▶ PodcastControl.xaml.cs
■ VisualStateManager 클래스의 GotoState 메소드를 사용해 Grid 컨트롤의 비주얼 상태를 변경하는 방법을 보여준다. ▶ FavoriteCommand.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 49 50 51 52 53 54 55 |
using System; using System.Windows.Input; namespace TestProject; /// <summary> /// 즐겨찾기 명령 /// </summary> public class FavoriteCommand: ICommand { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 변경시 - CanExecuteChanged /// <summary> /// 실행 가능 여부 변경시 /// </summary> public event EventHandler CanExecuteChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 구하기 - CanExecute(parameter) /// <summary> /// 실행 가능 여부 구하기 /// </summary> /// <param name="parameter">매개 변수</param> /// <returns>실행 가능 여부</returns> public bool CanExecute(object parameter) { return true; } #endregion #region 실행하기 - Execute(parameter) /// <summary> /// 실행하기 /// </summary> /// <param name="parameter">매개 변수</param> public void Execute(object parameter) { Podcast podcast = parameter as Podcast; podcast.IsFavorite = !podcast.IsFavorite; } #endregion } |
▶ Podcast.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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
using System.ComponentModel; namespace TestProject; /// <summary> /// 팟캐스트 /// </summary> public class Podcast : INotifyPropertyChanged { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 속성 변경시 - PropertyChanged /// <summary> /// 속성 변경시 /// </summary> public event PropertyChangedEventHandler PropertyChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 즐겨찾기 여부 /// </summary> private bool isFavorite = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 설명 - Description /// <summary> /// 설명 /// </summary> public string Description { get; set; } #endregion #region 즐겨찾기 여부 - IsFavorite /// <summary> /// 즐겨찾기 여부 /// </summary> public bool IsFavorite { get { return this.isFavorite; } set { this.isFavorite = value; FirePropertyChangedEvent("IsFavorite"); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName) /// <summary> /// 속성 변경시 이벤트 발생시키기 /// </summary> /// <param name="propertyName">속성명</param> private void FirePropertyChangedEvent(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion } |
▶ PodcastControl.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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<UserControl x:Class="TestProject.PodcastControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" IsTabStop="True" UseSystemFocusVisuals="True"> <UserControl.Resources> <SymbolIconSource x:Key="FavoriteSymbolIconSourceKey" Symbol="Favorite" /> <SwipeItems x:Key="RightSwipeItemsKey" Mode="Reveal"> <SwipeItem Background="Yellow" IconSource="{StaticResource FavoriteSymbolIconSourceKey}" Text="Favorite" Invoked="swipeItem_Invoked" /> </SwipeItems> </UserControl.Resources> <UserControl.ContextFlyout> <MenuFlyout> <MenuFlyoutItem Text="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </MenuFlyout> </UserControl.ContextFlyout> <SwipeControl RightItems="{StaticResource RightSwipeItemsKey}"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="HoveringStates"> <VisualState x:Name="HoverButtonsShown"> <VisualState.Setters> <Setter Target="hoverAreaGrid.Visibility" Value="Visible" /> </VisualState.Setters> </VisualState> <VisualState x:Name="HoverButtonsHidden" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid Margin="10 0 10 0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0" Margin="5" Spacing="10"> <TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="{x:Bind Podcast.Title, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.Description, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.IsFavorite, Mode=OneWay}" /> </StackPanel> <Grid Name="hoverAreaGrid" Grid.Column="1" VerticalAlignment="Stretch" Visibility="Collapsed"> <AppBarButton VerticalAlignment="Center" IsTabStop="False" Icon="OutlineStar" Label="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </Grid> </Grid> </SwipeControl> </UserControl> |
■ AppBarButton 엘리먼트의 Command/CommandParameter 속성을 사용해 버튼 클릭시 명령을 실행하는 방법을 보여준다. ▶ FavoriteCommand.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 49 50 51 52 53 54 55 |
using System; using System.Windows.Input; namespace TestProject; /// <summary> /// 즐겨찾기 명령 /// </summary> public class FavoriteCommand: ICommand { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 변경시 - CanExecuteChanged /// <summary> /// 실행 가능 여부 변경시 /// </summary> public event EventHandler CanExecuteChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행 가능 여부 구하기 - CanExecute(parameter) /// <summary> /// 실행 가능 여부 구하기 /// </summary> /// <param name="parameter">매개 변수</param> /// <returns>실행 가능 여부</returns> public bool CanExecute(object parameter) { return true; } #endregion #region 실행하기 - Execute(parameter) /// <summary> /// 실행하기 /// </summary> /// <param name="parameter">매개 변수</param> public void Execute(object parameter) { Podcast podcast = parameter as Podcast; podcast.IsFavorite = !podcast.IsFavorite; } #endregion } |
▶ Podcast.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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
using System.ComponentModel; namespace TestProject; /// <summary> /// 팟캐스트 /// </summary> public class Podcast : INotifyPropertyChanged { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 속성 변경시 - PropertyChanged /// <summary> /// 속성 변경시 /// </summary> public event PropertyChangedEventHandler PropertyChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 즐겨찾기 여부 /// </summary> private bool isFavorite = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 설명 - Description /// <summary> /// 설명 /// </summary> public string Description { get; set; } #endregion #region 즐겨찾기 여부 - IsFavorite /// <summary> /// 즐겨찾기 여부 /// </summary> public bool IsFavorite { get { return this.isFavorite; } set { this.isFavorite = value; FirePropertyChangedEvent("IsFavorite"); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName) /// <summary> /// 속성 변경시 이벤트 발생시키기 /// </summary> /// <param name="propertyName">속성명</param> private void FirePropertyChangedEvent(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion } |
▶ PodcastControl.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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<UserControl x:Class="TestProject.PodcastControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" IsTabStop="True" UseSystemFocusVisuals="True"> <UserControl.Resources> <SymbolIconSource x:Key="FavoriteSymbolIconSourceKey" Symbol="Favorite" /> <SwipeItems x:Key="RightSwipeItemsKey" Mode="Reveal"> <SwipeItem Background="Yellow" IconSource="{StaticResource FavoriteSymbolIconSourceKey}" Text="Favorite" Invoked="swipeItem_Invoked" /> </SwipeItems> </UserControl.Resources> <UserControl.ContextFlyout> <MenuFlyout> <MenuFlyoutItem Text="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </MenuFlyout> </UserControl.ContextFlyout> <SwipeControl RightItems="{StaticResource RightSwipeItemsKey}"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="HoveringStates"> <VisualState x:Name="HoverButtonsShown"> <VisualState.Setters> <Setter Target="hoverAreaGrid.Visibility" Value="Visible" /> </VisualState.Setters> </VisualState> <VisualState x:Name="HoverButtonsHidden" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid Margin="10 0 10 0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0" Margin="5" Spacing="10"> <TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="{x:Bind Podcast.Title, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.Description, Mode=OneWay}" /> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind Podcast.IsFavorite, Mode=OneWay}" /> </StackPanel> <Grid Name="hoverAreaGrid" Grid.Column="1" VerticalAlignment="Stretch" Visibility="Collapsed"> <AppBarButton VerticalAlignment="Center" IsTabStop="False" Icon="OutlineStar" Label="Favorite" Command="{StaticResource FavoriteCommandKey}" CommandParameter="{x:Bind Podcast, Mode=OneWay}" /> </Grid> </Grid> </SwipeControl> </UserControl> |
▶
■ 모든 입력 형식에 대한 컬렉션 명령을 만드는 방법을 보여준다. ※ ICommand 인터페이스, UserControl 클래스 ContextFlyout 속성, SwipeItem 클래스 Invoke 이벤트, KeyboardAccelerator
■ GridView 엘리먼트의 SelectionMode/IsMultiSelectCheckBoxEnabled 속성을 사용해 선택 모드가 Multiple인 경우 체크 박스를 숨기는 방법을 보여준다. ※ SelectionMode 속성이 Multiple인 경우 체크 박스가
■ GridView 엘리먼트의 ItemTemplate 속성을 사용해 항목을 표시하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를
■ ListView 엘리먼트의 ItemContainerStyle 속성을 사용해 항목 컨테이너 속성을 설정하는 방법을 보여준다. (ListViewItem 객체) ※ ListViewItem의 컨텐츠는 기본적으로 왼쪽에 맞추어진다 ※ 즉
■ ListView 엘리먼트의 ItemTemplate 속성을 사용해 항목을 표시하는 방법을 보여준다. ※ ItemTemplate 및 DisplayMemberPath를 동시에 사용할 수 없다. 두 속성을 모두 설정한
■ ListView 엘리먼트의 DisplayMemberPath 속성을 사용해 항목을 표시하는 방법을 보여준다. ※ ItemTemplate 및 DisplayMemberPath를 동시에 사용할 수 없다. 두 속성을 모두 설정한
■ RuntimeReflectionExtensions 클래스의 GetRuntimeProperties 확장 메소드를 사용해 Colors 클래스의 색상 정적 속성들에서 색상 딕셔너리를 구하는 방법을 보여준다. ▶ 예제 코드 (C#)
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 |
using System.Collections.Generic; using System.Reflection; using Windows.UI; using Microsoft.UI; IEnumerable<PropertyInfo> propertyInfoEnumerable = typeof(Colors).GetRuntimeProperties(); List<Color> colorList = new List<Color>(); foreach(PropertyInfo propertyInfo in propertyInfoEnumerable) { if(!propertyInfo.GetMethod.IsStatic) { continue; } if(propertyInfo.PropertyType != typeof(Color)) { continue; } Color color = (Color)propertyInfo.GetValue(null); colorList.Add(color); } |
■ RuntimeReflectionExtensions 클래스의 GetRuntimeProperties 확장 메소드를 사용해 특정 타입의 속성 열거 가능형을 구하는 방법을 보여준다. ▶ 예제 코드 1 (C#)
1 2 3 4 5 6 7 8 |
using System.Collections.Generic; using System.Reflection; using Microsoft.UI; IEnumerable<PropertyInfo> propertyInfoEnumerable = typeof(Colors).GetRuntimeProperties(); |
▶
■ ListView 엘리먼트의 ItemTemplate 속성을 사용해 항목을 표시하는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를
■ Compositor 클래스를 사용해 화면 배경의 브러시 애니메이션을 만드는 방법을 보여준다. ※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다. ※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType
■ CompositionColorGradientStop 클래스의 StartAnimation 메소드를 사용해 브러시 애니메이션을 시작하는 방법을 보여준다. ▶ 예제 코드 (C#)
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 49 |
using System; using System.Numerics; using Microsoft.UI; using Microsoft.UI.Composition; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Hosting; // ... Grid grid = null; // ... Visual gridVisual = ElementCompositionPreview.GetElementVisual(grid); Compositor compositor = gridVisual.Compositor; SpriteVisual spriteVisual = compositor.CreateSpriteVisual(); spriteVisual.Size = new Vector2((float)grid.ActualWidth, (float)grid.ActualHeight); ElementCompositionPreview.SetElementChildVisual(grid, spriteVisual); CompositionLinearGradientBrush compositionLinearGradientBrush = compositor.CreateLinearGradientBrush(); compositionLinearGradientBrush.StartPoint = new Vector2(0, 0); compositionLinearGradientBrush.EndPoint = new Vector2(1, 1); CompositionColorGradientStop compositionColorGradientStop1 = compositor.CreateColorGradientStop(0.0f, Colors.Transparent); CompositionColorGradientStop compositionColorGradientStop2 = compositor.CreateColorGradientStop(1.0f, Colors.Blue ); compositionLinearGradientBrush.ColorStops.Add(compositionColorGradientStop1); compositionLinearGradientBrush.ColorStops.Add(compositionColorGradientStop2); spriteVisual.Brush = compositionLinearGradientBrush; ScalarKeyFrameAnimation offsetScalarKeyFrameAnimation = compositor.CreateScalarKeyFrameAnimation(); offsetScalarKeyFrameAnimation.InsertKeyFrame(0.0f, -1.0f); offsetScalarKeyFrameAnimation.InsertKeyFrame(1.0f, 1.0f); offsetScalarKeyFrameAnimation.IterationBehavior = AnimationIterationBehavior.Forever; offsetScalarKeyFrameAnimation.Duration = TimeSpan.FromSeconds(1.5); compositionColorGradientStop1.StartAnimation("Offset", offsetScalarKeyFrameAnimation); compositionColorGradientStop2.StartAnimation("Offset", offsetScalarKeyFrameAnimation); |
■ Compositor 클래스의 CreateLinearGradientBrush 메소드를 사용해 CompositionLinearGradientBrush 객체를 만드는 방법을 보여준다. ▶ 예제 코드 (C#)
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 |
using System.Numerics; using Microsoft.UI; using Microsoft.UI.Composition; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Hosting; // ... Grid grid; // ... Visual gridVisual = ElementCompositionPreview.GetElementVisual(grid); Compositor compositor = gridVisual.Compositor; SpriteVisual spriteVisual = compositor.CreateSpriteVisual(); spriteVisual.Size = new Vector2((float)grid.ActualWidth, (float)grid.ActualHeight); ElementCompositionPreview.SetElementChildVisual(grid, spriteVisual); CompositionLinearGradientBrush compositionLinearGradientBrush = compositor.CreateLinearGradientBrush(); compositionLinearGradientBrush.StartPoint = new Vector2(0, 0); compositionLinearGradientBrush.EndPoint = new Vector2(1, 1); CompositionColorGradientStop compositionColorGradientStop1 = compositor.CreateColorGradientStop(0.0f, Colors.Transparent); CompositionColorGradientStop compositionColorGradientStop2 = compositor.CreateColorGradientStop(1.0f, Colors.Blue ); compositionLinearGradientBrush.ColorStops.Add(compositionColorGradientStop1); compositionLinearGradientBrush.ColorStops.Add(compositionColorGradientStop2); spriteVisual.Brush = compositionLinearGradientBrush; |
■ ElementCompositionPreview 클래스의 SetElementChildVisual 정적 메소드를 사용해 엘리먼트의 자식 비주얼을 설정하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using System.Numerics; using Microsoft.UI.Composition; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Hosting; // ... Grid grid; // ... Visual gridVisual = ElementCompositionPreview.GetElementVisual(grid); Compositor compositor = gridVisual.Compositor; SpriteVisual spriteVisual = compositor.CreateSpriteVisual(); spriteVisual.Size = new Vector2((float)grid.ActualWidth, (float)grid.ActualHeight); ElementCompositionPreview.SetElementChildVisual(grid, spriteVisual); |