Skip to content

Commit

Permalink
Merge pull request #24 from egvijayanand/working
Browse files Browse the repository at this point in the history
Blazor Interop project updated to .NET MAUI RC1 release with App Theming support
  • Loading branch information
egvijayanand authored Apr 17, 2022
2 parents 6c87ea4 + 27e5326 commit 8e3d498
Show file tree
Hide file tree
Showing 20 changed files with 675 additions and 134 deletions.
57 changes: 30 additions & 27 deletions src/MauiBlazorApp/MauiBlazorApp/App.xaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiBlazorApp"
x:Class="MauiBlazorApp.App">
<Application
x:Class="MauiBlazorApp.App"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiBlazorApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary Source="Resources/Styles.xaml">
<!-- Additional Styles -->
<Thickness x:Key="ApplePadding">30,60,30,30</Thickness>
<Thickness x:Key="DefaultPadding">30</Thickness>

<x:Double x:Key="ItemSpacing">10</x:Double>

<Color x:Key="PrimaryColor">#512BDF</Color>
<Color x:Key="SecondaryColor">White</Color>
<Style ApplyToDerivedTypes="True" TargetType="StackBase">
<Setter Property="Spacing" Value="{StaticResource ItemSpacing}" />
</Style>

<Style TargetType="StackBase"
ApplyToDerivedTypes="True">
<Setter Property="Spacing"
Value="{StaticResource ItemSpacing}" />
<Style x:Key="ContentArea" TargetType="Grid">
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource BackgroundLight}}" />
</Style>

<Style TargetType="Label"
ApplyToDerivedTypes="True">
<Setter Property="TextColor"
Value="{DynamicResource PrimaryColor}" />
<Setter Property="FontFamily"
Value="OpenSansRegular" />
<Style x:Key="MauiLabel" TargetType="Label">
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource Primary}}" />
</Style>

<Style TargetType="Button"
ApplyToDerivedTypes="True">
<Setter Property="TextColor"
Value="{DynamicResource SecondaryColor}" />
<Setter Property="FontFamily"
Value="OpenSansRegular" />
<Setter Property="BackgroundColor"
Value="{DynamicResource PrimaryColor}" />
<Setter Property="Padding"
Value="14,10" />
<Style x:Key="Action" TargetType="Button">
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource BackgroundLight}}" />
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource TextDark}, Light={StaticResource TextLight}}" />
<Setter Property="FontFamily" Value="{StaticResource AppFont}" />
<Setter Property="FontSize" Value="{StaticResource AppFontSize}" />
<Setter Property="Padding" Value="14,10" />
</Style>

<Style
x:Key="PrimaryAction"
BasedOn="{StaticResource Action}"
TargetType="Button">
<Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="TextColor" Value="{StaticResource White}" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
2 changes: 1 addition & 1 deletion src/MauiBlazorApp/MauiBlazorApp/BlazorPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private void OnStateChanged()
lblCounter.Text = $"The current count is: {_state.CurrentCount}";
}

private void Counter_Clicked(object sender, EventArgs e)
private void Counter_Clicked(object? sender, EventArgs e)
{
_state.IncrementCount();
}
Expand Down
30 changes: 19 additions & 11 deletions src/MauiBlazorApp/MauiBlazorApp/BlazorPage.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/MauiBlazorApp/MauiBlazorApp/Imports.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
global using CommunityToolkit.Maui.Markup;

global using static CommunityToolkit.Maui.Markup.GridRowsColumns;
global using static CommunityToolkit.Maui.Markup.GridRowsColumns;

global using static VijayAnand.MauiToolkit.Markup.Utility;
57 changes: 29 additions & 28 deletions src/MauiBlazorApp/MauiBlazorApp/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,42 @@ private void InitializeComponent()
{
Content = new ScrollView()
{
Content = new Grid()
Content = new StackLayout()
{
RowSpacing = 25,
RowDefinitions = Rows.Define(Auto, Auto, Auto, Auto, Star),
Spacing = 25,
Children =
{
new Label() { Text = "Hello, World!" }.Row(0)
.FontSize(32)
.CenterHorizontal()
.SemanticHeading(SemanticHeadingLevel.Level1),
new Label() { Text = "Welcome to .NET Multi-platform App UI" }.Row(1)
.FontSize(18)
.CenterHorizontal()
.SemanticHeading(SemanticHeadingLevel.Level1)
.SemanticDesc("Welcome to dot net Multi platform App U I"),
new Label() { Text = "Current count: 0" }.Row(2)
.Bold()
.FontSize(18)
.CenterHorizontal()
.Assign(out counter),
new Button() { Text = "Click me" }.Row(3)
.Bold()
.CenterHorizontal()
.Invoke(btn => btn.Clicked += OnCounterClicked)
.SemanticHint("Counts the number of times you click"),
new Image() { Source = "dotnet_bot.png" }.Row(4)
.Size(250, 310)
.CenterHorizontal()
.SemanticDesc("Cute dot net bot waving hi to you!"),
new Label()
{
Style = AppResource<Style>("MauiLabel"),
Text = "Hello, World!",
}.FontSize(32).CenterHorizontal().SemanticHeading(SemanticHeadingLevel.Level1),
new Label()
{
Style = AppResource<Style>("MauiLabel"),
Text = "Welcome to .NET Multi-platform App UI",
}.FontSize(18).CenterHorizontal().SemanticDesc("Welcome to dot net Multi platform App U I").SemanticHeading(SemanticHeadingLevel.Level1),
new Label()
{
FontAttributes = FontAttributes.Bold,
Style = AppResource<Style>("MauiLabel"),
Text = "Current count: 0",
}.FontSize(18).CenterHorizontal().Assign(out counter),
new Button()
{
Style = AppResource<Style>("PrimaryAction"),
Text = "Click me",
}.CenterHorizontal().Invoke(btn => btn.Clicked += OnCounterClicked).SemanticHint("Counts the number of times you click"),
new Image()
{
Source = "dotnet_bot.png",
}.Height(310).Width(250).CenterHorizontal().SemanticDesc("Cute dot net bot waving hi to you!"),
}
}.Padding(Device.RuntimePlatform switch { Device.iOS => new Thickness(30, 60, 30, 30), _ => new Thickness(30) })
}.Padding(30)
};
}

private void OnCounterClicked(object sender, EventArgs e)
private void OnCounterClicked(object? sender, EventArgs e)
{
count++;
counter.Text = $"Current count: {count}";
Expand Down
24 changes: 6 additions & 18 deletions src/MauiBlazorApp/MauiBlazorApp/MauiBlazorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<!-- .NET MAUI -->
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>

<!-- Project Options -->
<Nullable>enable</Nullable>
Expand All @@ -27,9 +26,6 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- Required for C# Hot Reload -->
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>

<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
Expand All @@ -52,16 +48,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="1.0.0-pre8" />
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="1.0.0-pre9" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="6.0.2" />
<PackageReference Include="VijayAnand.MauiBlazor.Markup" Version="1.0.0-pre4" />
<PackageReference Include="VijayAnand.MauiToolkit" Version="1.0.0-pre2" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
<!-- Required - WinUI does not yet have buildTransitive for everything -->
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.30" />
<PackageReference Include="VijayAnand.MauiBlazor.Markup" Version="1.0.0-pre5" />
<PackageReference Include="VijayAnand.MauiToolkit" Version="1.0.0-pre7" />
</ItemGroup>

<ItemGroup>
Expand All @@ -78,14 +68,12 @@
<MauiXaml Update="App.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Resources\Styles.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="WebPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>

</Project>
15 changes: 9 additions & 6 deletions src/MauiBlazorApp/MauiBlazorApp/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components.WebView.Maui;
using RazorLib;
using RazorLib;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

Expand All @@ -11,14 +10,18 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();

builder.RegisterBlazorMauiWebView()
.UseMauiApp<App>()
builder.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSansRegular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Regular.ttf", "OpenSans400");
fonts.AddFont("OpenSans-SemiBold.ttf", "OpenSans600");
});

builder.Services.AddBlazorWebView();
builder.Services.AddMauiBlazorWebView();

#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
#endif

builder.Services.AddSingleton<AppState>();
builder.Services.AddSingleton<BlazorPage>();
Expand Down
11 changes: 6 additions & 5 deletions src/MauiBlazorApp/MauiBlazorApp/Platforms/Windows/App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<maui:MauiWinUIApplication 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:MauiBlazorApp.WinUI"
x:Class="MauiBlazorApp.WinUI.App">
<maui:MauiWinUIApplication
x:Class="MauiBlazorApp.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MauiBlazorApp.WinUI"
xmlns:maui="using:Microsoft.Maui">

</maui:MauiWinUIApplication>
7 changes: 0 additions & 7 deletions src/MauiBlazorApp/MauiBlazorApp/Platforms/Windows/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,5 @@ public App()
}

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

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
base.OnLaunched(args);

Microsoft.Maui.Essentials.Platform.OnLaunched(args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
</Resources>

<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements />
</Application>
</Applications>
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 8e3d498

Please sign in to comment.