728x90
반응형
C# 코드에 정의된 static 필드를 xaml 단에서 사용할때 사용하는것이 x:static 태그이다
먼저 static 필드 정의
namespace MauiApp1.Defines;
public static class Constants
{
public static readonly string SfListViewTitle = "SfListView Test";
}
xaml 단에서 사용
<ContentPage x:Class="MauiApp1.SfListViewTestView"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
......
xmlns:local="clr-namespace:MauiApp1.Defines"
.......>
<Label
Text="{x:Static local:Constants.SfListViewTitle}"
HorizontalOptions="Center"
Margin="5">
</Label>
...
</ContentPage>
staticExtension 이라고 확장을 통해 사용도 가능하지만 위 일반적인 방법이 인텔리센스가 사용가능해 코딩하기 편한것 같다.
또한, 필드 명이 바뀐경우 자동으로 바꿔주고 만약 xaml 단이 바뀌지 않은 경우 오류도 도출하기 때문에 관리하기가 용이하다.
반응형
'Xamarin_MAUI' 카테고리의 다른 글
[.NET MAUI] Handler 사용하기 (0) | 2022.03.08 |
---|---|
[.NET MAUI] x:Reference 사용 (0) | 2022.03.07 |
[.NET MAUI] x:static 사용하기 (0) | 2022.03.03 |
[.NET MAUI] 플래폼(Android,iOS)에 따른 code 및 xaml 단 처리 방법 (0) | 2022.03.01 |
[.NET MAUI] SfListView 선택 항목 디자인 처리 (0) | 2022.03.01 |
[.NET MAUI] Syncfusion 의 SfListView 사용하기 (0) | 2022.03.01 |