-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from egvijayanand/working
Logic moved to Razor Class Library and Shared AppState with .NET MAUI
- Loading branch information
Showing
25 changed files
with
361 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
using Microsoft.AspNetCore.Components.WebView.Maui; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls; | ||
using RazorLib; | ||
using System; | ||
|
||
namespace MauiBlazorApp | ||
{ | ||
public class BlazorPage : ContentPage | ||
public partial class BlazorPage : ContentPage, IDisposable | ||
{ | ||
public BlazorPage() | ||
private readonly AppState _state; | ||
|
||
public BlazorPage(AppState appState) | ||
{ | ||
SetDynamicResource(BackgroundColorProperty, "SecondaryColor"); | ||
InitializeComponent(); | ||
_state = appState; | ||
_state.OnChanged += OnStateChanged; | ||
} | ||
|
||
var blazor = new BlazorWebView() | ||
{ | ||
HostPage = "wwwroot/index.html" | ||
}; | ||
private void OnStateChanged() | ||
{ | ||
lblCounter.Text = $"The current count is: {_state.CurrentCount}"; | ||
} | ||
|
||
blazor.RootComponents.Add(new() | ||
{ | ||
ComponentType = typeof(Gateway), | ||
Selector = "#app" | ||
}); | ||
private void Counter_Clicked(object sender, EventArgs e) | ||
{ | ||
_state.IncrementCount(); | ||
} | ||
|
||
Content = blazor; | ||
public void Dispose() | ||
{ | ||
_state.OnChanged -= OnStateChanged; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace MauiBlazorApp.Controls | ||
{ | ||
public class TextButton : Button | ||
{ | ||
public TextButton(string text) | ||
{ | ||
Text = text; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace MauiBlazorApp.Controls | ||
{ | ||
public class TextLabel : Label | ||
{ | ||
public TextLabel(string text) | ||
{ | ||
Text = text; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Router AppAssembly="@GetType().Assembly"> | ||
<Router AppAssembly="@GetType().Assembly" AdditionalAssemblies="new[] { typeof(Counter).Assembly }"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p>Sorry, there's nothing at this address.</p> | ||
<LayoutView Layout="@typeof(ErrorLayout)"> | ||
<p class="validation-message">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Maui; | ||
using System; | ||
|
||
namespace BlazorApp.Services | ||
{ | ||
public static class AppService | ||
{ | ||
public static TService GetService<TService>() => Current.GetService<TService>(); | ||
|
||
public static IServiceProvider Current => | ||
#if ANDROID | ||
MauiApplication.Current.Services; | ||
#elif IOS || MACCATALYST | ||
MauiUIApplicationDelegate.Current.Services; | ||
#elif WINDOWS10_0_17763_0_OR_GREATER | ||
MauiWinUIApplication.Current.Services; | ||
#else | ||
null; | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
using RazorLib; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MauiBlazorApp | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class WebPage : ContentPage | ||
public partial class WebPage : ContentPage, IDisposable | ||
{ | ||
public WebPage() | ||
private readonly AppState _state; | ||
|
||
public WebPage(AppState appState) | ||
{ | ||
InitializeComponent(); | ||
_state = appState; | ||
_state.OnChanged += OnStateChanged; | ||
} | ||
|
||
private void OnStateChanged() | ||
{ | ||
lblCounter.Text = $"The current count is: {_state.CurrentCount}"; | ||
} | ||
|
||
private void Counter_Clicked(object sender, EventArgs e) | ||
{ | ||
_state.IncrementCount(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_state.OnChanged -= OnStateChanged; | ||
} | ||
} | ||
} |
Oops, something went wrong.