C
C#13mo ago
! 휘백

Different design in maui

Hello, I am developing a cross-platform program using MAUI. By the way, I want to apply a different design for each mobile/desktop, what should I do?
8 Replies
Cattywampus
Cattywampus13mo ago
Two ways you can do this 1. Conditional Compilation (easy but expect lotta boilerplate) 2. Xaml approach (a bit tedious but much cleaner) for no.1 you can do this
#if ANDROID
myLayout.Add(new MyAndroidView());
#elif IOS
myLayout.Add(new MyIOSView());
#endif
#if ANDROID
myLayout.Add(new MyAndroidView());
#elif IOS
myLayout.Add(new MyIOSView());
#endif
simple, but as said, full of boilerplate codes ... for xaml approach :
<ContentView>
<OnPlatform x:TypeArguments="View">
<On Platform="Android">
//do something
</On>
<On Platform="iOS">
//do something
</On>
</OnPlatform>
</ContentView>
<ContentView>
<OnPlatform x:TypeArguments="View">
<On Platform="Android">
//do something
</On>
<On Platform="iOS">
//do something
</On>
</OnPlatform>
</ContentView>
I say, do the xaml one
! 휘백
! 휘백OP13mo ago
Thanks very much!
Cattywampus
Cattywampus13mo ago
goodluck (how can I close this?)
! 휘백
! 휘백OP13mo ago
maybe, the bot automaticly close this But just to ask you one more question, where should I insert that XAML code?
Cattywampus
Cattywampus13mo ago
well, in your xaml obviously 😄 see the introduction for .net Maui, it covers all things you want to know about xaml in maui
! 휘백
! 휘백OP13mo ago
ok thanks
Cattywampus
Cattywampus13mo ago
np
CrhisLit
CrhisLit13mo ago
Hello friends, I need help, this is my code in .NET MAUI, and I want the application to start if there is a Token saved in SecureStorage, because when starting the application it does not load, that is, the startup code does not reach that line of code that says "Choose()", so you can choose whether to load with the AppShell or the navigation "Code" public App() { InitializeComponent(); Choose(); } public async void Choose() { string tok = SecureStorage.GetAsync("token").Result; if (!string.IsNullOrEmpty(tok)) { MainPage = new NavigationPage(new Home()) { //FlyoutBackgroundColor = Color.FromHex("#D68900"), BarBackground = Color.FromArgb("#FFB04B"), BarTextColor = Color.FromRgb(255, 255, 255), }; } else { MainPage = new AppShell() { FlyoutBackgroundColor = Color.FromArgb("#D68900"), //BarBackground = Color.FromHex("#FFB04B"), // BarTextColor = Color.FromRgb(255, 255, 255), }; } }
Want results from more Discord servers?
Add your server