■ PersonPicture 엘리먼트의 ProfilePicture/DisplayName/Initials 속성을 사용하는 방법을 보여준다.
▶ BooleanToValueConverter.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 |
using System; using Microsoft.UI.Xaml.Data; namespace TestProject { /// <summary> /// 불린값→값 변환자 /// </summary> public sealed class BooleanToValueConverter : 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) { return ((bool)sourceValue) ? parameter : null; } #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) { throw new NotImplementedException(); } #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 38 39 40 41 42 43 44 45 46 |
<?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}"> <Page.Resources> <local:BooleanToValueConverter x:Key="BooleanToValueConverterKey" /> </Page.Resources> <Grid Margin="10"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <PersonPicture Name="personPicture" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Height="300" ProfilePicture="{Binding IsChecked, ElementName=profileImageRadioButton, Converter={StaticResource BooleanToValueConverterKey}, ConverterParameter='https://learn.microsoft.com/windows/uwp/contacts-and-calendar/images/shoulder-tap-static-payload.png'}" DisplayName="{x:Bind displayNameRadioButton.IsChecked, Mode=OneWay, Converter={StaticResource BooleanToValueConverterKey}, ConverterParameter='Jane Doe'}" Initials="{x:Bind initialsRadioButton.IsChecked, Mode=OneWay, Converter={StaticResource BooleanToValueConverterKey}, ConverterParameter='SB'}" /> <RadioButtons Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Header="Profile type"> <RadioButton Name="profileImageRadioButton" Content="Profile Image" IsChecked="True" /> <RadioButton Name="displayNameRadioButton" Content="Display Name" /> <RadioButton Name="initialsRadioButton" Content="Initials" /> </RadioButtons> </Grid> </Page> |