■ Binding 태그 확장의 StringFormat 속성을 사용하는 방법을 보여준다.
▶ 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 47 48 49 50 51 52 53 54 55 56 57 58 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:sys="clr-namespace:System;assembly=netstandard"> <ContentPage.Resources> <Style TargetType="Label"> <Setter Property="HorizontalTextAlignment" Value="Center" /> </Style> <Style TargetType="BoxView"> <Setter Property="HeightRequest" Value="2" /> <Setter Property="Margin" Value="0,30" /> <Setter Property="Color" Value="Blue" /> </Style> </ContentPage.Resources> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Margin="10"> <Slider x:Name="slider" /> <Label Text="{Binding Source={x:Reference slider}, Path=Value, StringFormat='슬라이더 값 : {0:F2}'}" /> <BoxView /> <TimePicker x:Name="timePicker" /> <Label Text="{Binding Source={x:Reference timePicker}, Path=Time, StringFormat='시간 범위 : {0:c}'}" /> <BoxView /> <Entry x:Name="entry" /> <Label Text="{Binding Source={x:Reference entry}, Path=Text, StringFormat='입력 텍스트 : "{0}"'}" /> <BoxView /> <StackLayout BindingContext="{x:Static sys:DateTime.Now}"> <Label HorizontalOptions="Start" Text="{Binding}" /> <Label HorizontalOptions="Start" Text="{Binding Path=Ticks, StringFormat='1/1/1일 이후 틱 수 : {0:N0}'}" /> <Label HorizontalOptions="Start" Text="{Binding StringFormat='{{0:MMMM}} 포맷 문자열 : {0:MMMM}'}" /> <Label HorizontalOptions="Start" Text="{Binding StringFormat='긴 형식 날짜 : {0:D}'}" /> </StackLayout> <BoxView /> <StackLayout BindingContext="{x:Static sys:Math.PI}"> <Label HorizontalOptions="Start" Text="{Binding}" /> <Label HorizontalOptions="Start" Text="{Binding StringFormat='소수점 4자리 PI 값 : {0:F4}'}" /> <Label HorizontalOptions="Start" Text="{Binding StringFormat='과학점 표기 PI 값 : {0:E7}'}" /> </StackLayout> </StackLayout> </ContentPage> |