BindingContext extension for viewmodels

This commit is contained in:
2024-09-03 12:53:21 +02:00
parent 155a966a9e
commit 5098909f97
2 changed files with 6 additions and 5 deletions
@@ -1,4 +1,5 @@
using System.ComponentModel;
using Net.Maui.Extensions.ControlFlow;
using System.ComponentModel;
using System.Core.Extensions;
using System.Extensions;
@@ -6,9 +7,9 @@ namespace Net.Maui.Extensions.Extensions;
public static class ContentPageExtensions
{
public static T GetBindingContext<T>(this ContentPage contentPage)
where T : INotifyPropertyChanged
public static T? GetBindingContext<T>(this IPageViewModel<T> page)
where T : class, INotifyPropertyChanged, new()
{
return contentPage.ThrowIfNull().BindingContext.Cast<T>();
return page.As<BindableObject>()?.ThrowIfNull()?.BindingContext.As<T>();
}
}
@@ -20,7 +20,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<Version>0.2.10</Version>
<Version>0.2.11</Version>
<Authors>Alexandru Macocian</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>