Skip to content

Commit

Permalink
Add Styling sample (#156)
Browse files Browse the repository at this point in the history
* Styling sample

* Complete with CommunityToolkit.Maui.Markup
  • Loading branch information
Dreamescaper authored Nov 2, 2024
1 parent 26bd7f2 commit 543bada
Show file tree
Hide file tree
Showing 35 changed files with 672 additions and 0 deletions.
21 changes: 21 additions & 0 deletions BlazorBindings.Maui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidationsSample", "sample
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HybridSample", "samples\HybridSample\HybridSample.csproj", "{013060C4-5EA1-4C03-9EA6-9DAB66A11AA5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StylingSample", "samples\StylingSample\StylingSample.csproj", "{96CC3244-0590-42F1-92B9-E69E49996254}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -258,6 +260,24 @@ Global
{013060C4-5EA1-4C03-9EA6-9DAB66A11AA5}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{013060C4-5EA1-4C03-9EA6-9DAB66A11AA5}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{013060C4-5EA1-4C03-9EA6-9DAB66A11AA5}.Release|iPhoneSimulator.Deploy.0 = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|iPhone.Build.0 = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|iPhone.Deploy.0 = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Debug|iPhoneSimulator.Deploy.0 = Debug|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|Any CPU.Build.0 = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|Any CPU.Deploy.0 = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|iPhone.ActiveCfg = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|iPhone.Build.0 = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|iPhone.Deploy.0 = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{96CC3244-0590-42F1-92B9-E69E49996254}.Release|iPhoneSimulator.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -276,6 +296,7 @@ Global
{5AC34CCA-967A-4A21-91BF-F0BD04129DCE} = {50192AAF-25B6-447A-99AA-BA8161DBB594}
{F27CF7EE-3A84-4915-ADA4-567629AB127E} = {50192AAF-25B6-447A-99AA-BA8161DBB594}
{013060C4-5EA1-4C03-9EA6-9DAB66A11AA5} = {50192AAF-25B6-447A-99AA-BA8161DBB594}
{96CC3244-0590-42F1-92B9-E69E49996254} = {50192AAF-25B6-447A-99AA-BA8161DBB594}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A645A7FF-3F09-414D-A391-7E50C3597F05}
Expand Down
12 changes: 12 additions & 0 deletions samples/StylingSample/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BlazorBindings.Maui;
using StylingSample.Resources;

namespace StylingSample;

public class App : BlazorBindingsApplication<AppShell>
{
public App(IServiceProvider services) : base(services)
{
Resources.Add(AppStyles.Default);
}
}
5 changes: 5 additions & 0 deletions samples/StylingSample/AppShell.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Shell>
<ShellContent Title="Home">
<MainPage />
</ShellContent>
</Shell>
51 changes: 51 additions & 0 deletions samples/StylingSample/MainPage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@page "/main"

<ContentPage Resources="AppStyles.Scoped">
<VerticalStackLayout Spacing="25"
Padding="new(30,0)"
VerticalOptions="LayoutOptions.Center">
<Image Source="dotNetBotSource"
HeightRequest="200"
HorizontalOptions="LayoutOptions.Center" />

<Label Text="Hello, World!"
FontSize="32"
HorizontalOptions="LayoutOptions.Center" />

<Label Text="Welcome to .NET Multi-platform App UI"
FontSize="18"
HorizontalOptions="LayoutOptions.Center" />

<Button Text="@ButtonText"
HorizontalOptions="LayoutOptions.Center"
OnClick="OnCounterClicked" />

<Button Text="Change App Theme" OnClick="ChangeAppTheme">
</Button>
</VerticalStackLayout>
</ContentPage>

@code {
ImageSource dotNetBotSource = ImageSource.FromFile("dotnet_bot.png");

int count = 0;

string ButtonText => count switch
{
0 => "Click me",
1 => $"Clicked 1 time",
_ => $"Clicked {count} times"
};

void OnCounterClicked()
{
count++;
}

void ChangeAppTheme()
{
MC.Application.Current!.UserAppTheme = MC.Application.Current!.UserAppTheme == AppTheme.Light
? AppTheme.Dark
: AppTheme.Light;
}
}
26 changes: 26 additions & 0 deletions samples/StylingSample/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BlazorBindings.Maui;
using Microsoft.Extensions.Logging;

namespace StylingSample;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiBlazorBindings()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
6 changes: 6 additions & 0 deletions samples/StylingSample/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
9 changes: 9 additions & 0 deletions samples/StylingSample/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace StylingSample;
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
14 changes: 14 additions & 0 deletions samples/StylingSample/Platforms/Android/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Android.App;
using Android.Runtime;

namespace StylingSample;
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
8 changes: 8 additions & 0 deletions samples/StylingSample/Platforms/MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Foundation;

namespace StylingSample;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
14 changes: 14 additions & 0 deletions samples/StylingSample/Platforms/MacCatalyst/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

38 changes: 38 additions & 0 deletions samples/StylingSample/Platforms/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- The Mac App Store requires you specify if the app uses encryption. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/itsappusesnonexemptencryption -->
<!-- <key>ITSAppUsesNonExemptEncryption</key> -->
<!-- Please indicate <true/> or <false/> here. -->

<!-- Specify the category for your app here. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationcategorytype -->
<!-- <key>LSApplicationCategoryType</key> -->
<!-- <string>public.app-category.YOUR-CATEGORY-HERE</string> -->
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
14 changes: 14 additions & 0 deletions samples/StylingSample/Platforms/MacCatalyst/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ObjCRuntime;
using UIKit;

namespace StylingSample;
public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
16 changes: 16 additions & 0 deletions samples/StylingSample/Platforms/Tizen/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using System;

namespace StylingSample;

internal class Program : MauiApplication
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

static void Main(string[] args)
{
var app = new Program();
app.Run(args);
}
}
15 changes: 15 additions & 0 deletions samples/StylingSample/Platforms/Tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="maui-application-id-placeholder" version="0.0.0" api-version="8" xmlns="http://tizen.org/ns/packages">
<profile name="common" />
<ui-application appid="maui-application-id-placeholder" exec="StylingSample.dll" multiple="false" nodisplay="false" taskmanage="true" type="dotnet" launch_mode="single">
<label>maui-application-title-placeholder</label>
<icon>maui-appicon-placeholder</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
</ui-application>
<shortcut-list />
<privileges>
<privilege>http://tizen.org/privilege/internet</privilege>
</privileges>
<dependencies />
<provides-appdefined-privileges />
</manifest>
8 changes: 8 additions & 0 deletions samples/StylingSample/Platforms/Windows/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<maui:MauiWinUIApplication
x:Class="StylingSample.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:StylingSample.WinUI">

</maui:MauiWinUIApplication>
23 changes: 23 additions & 0 deletions samples/StylingSample/Platforms/Windows/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.UI.Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace StylingSample.WinUI;
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : MauiWinUIApplication
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

46 changes: 46 additions & 0 deletions samples/StylingSample/Platforms/Windows/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">

<Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="0.0.0.0" />

<mp:PhoneIdentity PhoneProductId="C507E0CC-F56B-4278-B6DD-35D73F90000B" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

<Properties>
<DisplayName>$placeholder$</DisplayName>
<PublisherDisplayName>User Name</PublisherDisplayName>
<Logo>$placeholder$.png</Logo>
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>

<Resources>
<Resource Language="x-generate" />
</Resources>

<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="$placeholder$"
Description="$placeholder$"
Square150x150Logo="$placeholder$.png"
Square44x44Logo="$placeholder$.png"
BackgroundColor="transparent">
<uap:DefaultTile Square71x71Logo="$placeholder$.png" Wide310x150Logo="$placeholder$.png" Square310x310Logo="$placeholder$.png" />
<uap:SplashScreen Image="$placeholder$.png" />
</uap:VisualElements>
</Application>
</Applications>

<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>

</Package>
15 changes: 15 additions & 0 deletions samples/StylingSample/Platforms/Windows/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="StylingSample.WinUI.app"/>

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!-- The combination of below two tags have the following effect:
1) Per-Monitor for >= Windows 10 Anniversary Update
2) System < Windows 10 Anniversary Update
-->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>
</assembly>
8 changes: 8 additions & 0 deletions samples/StylingSample/Platforms/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Foundation;

namespace StylingSample;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Loading

0 comments on commit 543bada

Please sign in to comment.