■ Popup 엘리먼트의 PlacementTarget/DesiredPlacement/IsOpen 속성을 사용해 팝업을 표시하는 방법을 보여준다.
※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다.
※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를 None으로 추가했다.
▶ NullableBooleanToBooleanConverter.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 |
using System; using Microsoft.UI.Xaml.Data; namespace TestProject; /// <summary> /// NULL 가능한 불린값↔불린값 변환자 /// </summary> public class NullableBooleanToBooleanConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, language) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="language">언어</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, string language) { if(sourceValue is bool?) { return (bool)sourceValue; } return false; } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, language) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="language">언어</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, string language) { if(sourceValue is bool) { return (bool)sourceValue; } return false; } #endregion } |
▶ MainPage.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 |
<?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" xmlns:local="using:TestProject" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <Page.Resources> <local:NullableBooleanToBooleanConverter x:Key="NullableBooleanToBooleanConverterKey" /> </Page.Resources> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="10"> <Popup Name="popup" PlacementTarget="{x:Bind toggleButton}" DesiredPlacement="TopEdgeAlignedLeft" IsOpen="{x:Bind toggleButton.IsChecked, Mode=OneWay, Converter={StaticResource NullableBooleanToBooleanConverterKey}}"> <Rectangle Name="rectangle" Margin="0 -30 0 -30" Width="200" Height="200" Fill="Lavender"> <Rectangle.Shadow> <ThemeShadow /> </Rectangle.Shadow> </Rectangle> </Popup> <ToggleButton Name="toggleButton" HorizontalAlignment="Center" Padding="10" Content="Show popup" /> </StackPanel> </Page> |
▶ MainPage.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 |
using System.Numerics; using Microsoft.UI.Xaml.Controls; namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.rectangle.Translation += new Vector3(0, 0, 32); } #endregion } |