■ x:Static 태그 확장에서 정적 필드를 참조하는 방법을 보여준다.
▶ ApplicationConstant.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 |
namespace TestProject; /// <summary> /// 애플리케이션 상수 /// </summary> public static class ApplicationConstant { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 배경 색상 /// </summary> public static readonly Color BackgroundColor = Colors.Aqua; /// <summary> /// 전경 색상 /// </summary> public static readonly Color ForegroundColor = Colors.Brown; #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 |
<?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" xmlns:local="clr-namespace:TestProject" Padding="10"> <StackLayout> <Label HorizontalOptions="Center" BackgroundColor="{x:Static local:ApplicationConstant.ForegroundColor}" TextColor="{x:Static local:ApplicationConstant.BackgroundColor}" FontSize="30" FontAttributes="Bold" Text="Hello, XAML!" /> <BoxView HorizontalOptions="Center" VerticalOptions="CenterAndExpand" WidthRequest="{x:Static sys:Math.PI}" HeightRequest="{x:Static sys:Math.E}" Color="{x:Static local:ApplicationConstant.ForegroundColor}" Scale="100" /> </StackLayout> </ContentPage> |