-
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #17 from AvantiPoint/dev/ds/updates
General Updates
- Loading branch information
Showing
24 changed files
with
354 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<PackageId>AvantiPoint.$(AssemblyName)</PackageId> | ||
</PropertyGroup> | ||
</Project> |
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,13 @@ | ||
<?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" | ||
x:Class="MauiMicroSample.App"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="Resources/Styles/Colors.xaml" /> | ||
<ResourceDictionary Source="Resources/Styles/Styles.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
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,9 @@ | ||
namespace MauiMicroSample; | ||
|
||
public partial class App : Application | ||
{ | ||
public App() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/MauiMicroMvvm.Templates/content/MauiMicroApp.1/App.xaml
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,13 @@ | ||
<?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" | ||
x:Class="MauiMicroApp._1.App"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="Resources/Styles/Colors.xaml" /> | ||
<ResourceDictionary Source="Resources/Styles/Styles.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
9 changes: 9 additions & 0 deletions
9
src/MauiMicroMvvm.Templates/content/MauiMicroApp.1/App.xaml.cs
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,9 @@ | ||
namespace MauiMicroApp._1; | ||
|
||
public partial class App : Application | ||
{ | ||
public App() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
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,27 @@ | ||
namespace MauiMicroMvvm.Behaviors; | ||
|
||
public sealed class BehaviorFactory : IBehaviorFactory | ||
{ | ||
private readonly IEnumerable<IRegisteredBehavior> _behaviors; | ||
private readonly IServiceProvider _services; | ||
|
||
public BehaviorFactory(IServiceProvider services, IEnumerable<IRegisteredBehavior> behaviors) | ||
{ | ||
ArgumentNullException.ThrowIfNull(services); | ||
_behaviors = behaviors ?? []; | ||
_services = services; | ||
} | ||
|
||
public void ApplyBehaviors(VisualElement element) | ||
{ | ||
foreach (var registration in _behaviors) | ||
{ | ||
if (!registration.ViewType.IsAssignableFrom(registration.ViewType)) | ||
continue; | ||
|
||
var behavior = registration.GetBehavior(); | ||
if (behavior is not null) | ||
element.Behaviors.Add(behavior); | ||
} | ||
} | ||
} |
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,24 @@ | ||
namespace MauiMicroMvvm.Behaviors; | ||
|
||
internal sealed class DelegateViewBehavior<TView>(Action<IServiceProvider, TView> onAttached, Action<IServiceProvider, TView> onDetached) : Behavior<TView> | ||
where TView : VisualElement | ||
{ | ||
private readonly Action<IServiceProvider, TView> _onAttached = onAttached; | ||
private readonly Action<IServiceProvider, TView> _onDetached = onDetached; | ||
|
||
protected override void OnAttachedTo(TView bindable) | ||
{ | ||
base.OnAttachedTo(bindable); | ||
var serviceProvider = bindable.Handler?.MauiContext?.Services; | ||
ArgumentNullException.ThrowIfNull(serviceProvider); | ||
_onAttached(serviceProvider, bindable); | ||
} | ||
|
||
protected override void OnDetachingFrom(TView bindable) | ||
{ | ||
base.OnDetachingFrom(bindable); | ||
var serviceProvider = bindable.Handler?.MauiContext?.Services; | ||
ArgumentNullException.ThrowIfNull(serviceProvider); | ||
_onDetached(serviceProvider, bindable); | ||
} | ||
} |
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,6 @@ | ||
namespace MauiMicroMvvm.Behaviors; | ||
|
||
public interface IBehaviorFactory | ||
{ | ||
void ApplyBehaviors(VisualElement element); | ||
} |
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,7 @@ | ||
namespace MauiMicroMvvm.Behaviors; | ||
|
||
public interface IRegisteredBehavior | ||
{ | ||
Type ViewType { get; } | ||
Behavior GetBehavior(); | ||
} |
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,10 @@ | ||
namespace MauiMicroMvvm.Behaviors; | ||
|
||
internal class RegisteredBehavior<TView, TBehavior>(IServiceProvider Services) : IRegisteredBehavior | ||
where TView : VisualElement | ||
where TBehavior : Behavior | ||
{ | ||
public Type ViewType => typeof(TView); | ||
|
||
public Behavior GetBehavior() => Services.GetRequiredService<TBehavior>(); | ||
} |
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,42 @@ | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace MauiMicroMvvm.Common; | ||
|
||
public static class MvvmHelpers | ||
{ | ||
public static void InvokeViewViewModelAction<T>(object? value, Action<T> action) | ||
{ | ||
if (value is T valueAsT) | ||
{ | ||
action(valueAsT); | ||
} | ||
|
||
if (value is BindableObject bindable) | ||
{ | ||
InvokeViewViewModelAction(bindable.BindingContext, action); | ||
} | ||
} | ||
|
||
public static async Task InvokeViewViewModelActionAsync<T>(object? value, Func<T, Task> action) | ||
{ | ||
if (value is T valueAsT) | ||
{ | ||
await action(valueAsT); | ||
} | ||
|
||
if (value is BindableObject bindable) | ||
{ | ||
await InvokeViewViewModelActionAsync(bindable.BindingContext, action); | ||
} | ||
} | ||
|
||
public static void Destroy(object? page) | ||
{ | ||
InvokeViewViewModelAction<IDisposable>(page, x => x.Dispose()); | ||
} | ||
|
||
public static Task DestroyAsync(object? page) | ||
{ | ||
return InvokeViewViewModelActionAsync<IAsyncDisposable>(page, x => x.DisposeAsync().AsTask()); | ||
} | ||
} |
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
Oops, something went wrong.