728x90
728x170
Android, iOS 에 따라서 코드 분기가 필요할때가 있다 Xamarin 에서도 기기적 특성으로 인해
사용한적이 많았는데 이부분은 Xamarin 껄 그대로 가져왔다.
xaml 단에서 사용방법은 OnPlatform 태그를 사용
( <OnPlatform> 테그를 쓰거나 직접 값을 지정할때 x:OnPlatform 을 사용하는 방식 )
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.NewPage"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView"
Title="NewPage"
Padding="10,10,10,100"
BackgroundColor="White">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0, 10, 0, 0" />
<On Platform="Android" Value="10, 10, 10, 10" />
</OnPlatform>
</ContentPage.Padding>
<StackLayout >
<StackLayout.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0, 10, 0, 0" />
<On Platform="Android" Value="10, 10, 10, 10" />
</OnPlatform>
</StackLayout.Margin>
<Label Text="Kei Soft 강준 (https://github.com/kei-soft)"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
TextColor="{x:OnPlatform iOS=Black, Android=Blue, UWP=Gray}"/>
<Button x:Name="sfListViewButton" Text="SfListView" Clicked="sfListViewButton_Clicked"/>
</StackLayout>
</ContentPage>
C# Code 는 Device.RuntimePlatform 으로 구분
if (Device.RuntimePlatform == Device.Android)
{
Padding = new Thickness(0, 10, 0, 0);
}
else if (Device.RuntimePlatform == Device.iOS)
{
Padding = new Thickness(10, 10, 10, 10);
}
728x90
그리드형
'C# > Xamarin Maui' 카테고리의 다른 글
[.NET MAUI] x:Reference 사용 (0) | 2022.03.07 |
---|---|
[.NET MAUI] x:static 사용하기 (0) | 2022.03.03 |
[.NET MAUI] SfListView 선택 항목 디자인 처리 (0) | 2022.03.01 |
[.NET MAUI] Syncfusion 의 SfListView 사용하기 (0) | 2022.03.01 |
[.NET MAUI] 이미지 , 폰트 추가 (0) | 2022.03.01 |