diff --git a/MVVMCrud/maui_net7/MVVMCrud.Example/FodyWeavers.xml b/MVVMCrud/maui_net7/MVVMCrud.Example/FodyWeavers.xml
new file mode 100644
index 0000000..d5abfed
--- /dev/null
+++ b/MVVMCrud/maui_net7/MVVMCrud.Example/FodyWeavers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/MVVMCrud/maui_net7/MVVMCrud.Example/FodyWeavers.xsd b/MVVMCrud/maui_net7/MVVMCrud.Example/FodyWeavers.xsd
new file mode 100644
index 0000000..69dbe48
--- /dev/null
+++ b/MVVMCrud/maui_net7/MVVMCrud.Example/FodyWeavers.xsd
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+ Used to control if the On_PropertyName_Changed feature is enabled.
+
+
+
+
+ Used to control if the Dependent properties feature is enabled.
+
+
+
+
+ Used to control if the IsChanged property feature is enabled.
+
+
+
+
+ Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.
+
+
+
+
+ Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.
+
+
+
+
+ Used to control if equality checks should use the Equals method resolved from the base class.
+
+
+
+
+ Used to control if equality checks should use the static Equals method resolved from the base class.
+
+
+
+
+ Used to turn off build warnings from this weaver.
+
+
+
+
+ Used to turn off build warnings about mismatched On_PropertyName_Changed methods.
+
+
+
+
+
+
+
+ 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.
+
+
+
+
+ A comma-separated list of error codes that can be safely ignored in assembly verification.
+
+
+
+
+ 'false' to turn off automatic generation of the XML Schema file.
+
+
+
+
+
\ No newline at end of file
diff --git a/MVVMCrud/maui_net7/MVVMCrud.Example/MVVMCrud.Example.csproj b/MVVMCrud/maui_net7/MVVMCrud.Example/MVVMCrud.Example.csproj
index 39e3a1b..6916dd0 100644
--- a/MVVMCrud/maui_net7/MVVMCrud.Example/MVVMCrud.Example.csproj
+++ b/MVVMCrud/maui_net7/MVVMCrud.Example/MVVMCrud.Example.csproj
@@ -33,6 +33,15 @@
false
+
+ false
+
+
+ false
+ Mac Developer
+ 3rd Party Mac Developer Installer
+ False
+
@@ -50,35 +59,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
ResXFileCodeGenerator
@@ -91,6 +73,9 @@
-
+
+
+
+
diff --git a/MVVMCrud/maui_net7/MVVMCrud.Example/MVVMCrud.Example.sln b/MVVMCrud/maui_net7/MVVMCrud.Example/MVVMCrud.Example.sln
new file mode 100644
index 0000000..db662a6
--- /dev/null
+++ b/MVVMCrud/maui_net7/MVVMCrud.Example/MVVMCrud.Example.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 25.0.1704.2
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVMCrud.Example", "MVVMCrud.Example.csproj", "{2D668148-6AD6-4E7C-8A42-7CCB7F6EC563}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {2D668148-6AD6-4E7C-8A42-7CCB7F6EC563}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2D668148-6AD6-4E7C-8A42-7CCB7F6EC563}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2D668148-6AD6-4E7C-8A42-7CCB7F6EC563}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2D668148-6AD6-4E7C-8A42-7CCB7F6EC563}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {5A6FE169-79E6-4F86-BCA9-94A419A2B400}
+ EndGlobalSection
+EndGlobal
diff --git a/MVVMCrud/maui_net7/MVVMCrud.Example/MauiProgram.cs b/MVVMCrud/maui_net7/MVVMCrud.Example/MauiProgram.cs
index 5d24d5c..4ba9acf 100644
--- a/MVVMCrud/maui_net7/MVVMCrud.Example/MauiProgram.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud.Example/MauiProgram.cs
@@ -1,5 +1,4 @@
-using CommunityToolkit.Maui;
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
using Microsoft.Maui.Controls.Hosting;
using MVVMCrud.Example.Utils.MVVMCrud;
using Prism.Navigation;
@@ -22,7 +21,6 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
- .UseMauiCommunityToolkit()
.UsePrism(prism =>
prism.RegisterTypes(containerRegistry =>
diff --git a/MVVMCrud/maui_net7/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs b/MVVMCrud/maui_net7/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs
index 45de2d6..5120561 100644
--- a/MVVMCrud/maui_net7/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud.Example/Utils/MVVMCrud/CustomMVVMCrud.cs
@@ -3,6 +3,7 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Security;
+using System.Resources;
using System.Security.Cryptography.X509Certificates;
using MVVMCrud.Models.ItemRoot;
using MVVMCrud.Utils;
@@ -15,11 +16,12 @@ public class CustomMVVMCrud : MVVMCrudApplication
{
public CustomMVVMCrud()
{
- AppResourceManager = AppResources.ResourceManager;
}
public override BaseRequestSetupResponse SetupBaseRequestSetupResponse() => new CustomBaseRequestSetupResponse();
+ public override ResourceManager SetupAppResourceManager() => AppResources.ResourceManager;
+
public override HttpClient SetupHttpClient()
{
HttpClientHandler handler = new HttpClientHandler
@@ -34,12 +36,13 @@ public override HttpClient SetupHttpClient()
return client;
}
- private bool CheckSSLConnection(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)
- {
- return true;
- }
+ private bool CheckSSLConnection(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)
+ {
+ return true;
+ }
+
- public override void SetupRootItemBase(RootItemBase rootItemBase)
+ public override void SetupRootItemBase(RootItemBase rootItemBase)
{
var httpCode = rootItemBase.HttpResponseCode;
diff --git a/MVVMCrud/maui_net7/MVVMCrud.Example/ViewModels/Post/PostPageViewModel.cs b/MVVMCrud/maui_net7/MVVMCrud.Example/ViewModels/Post/PostPageViewModel.cs
index edcd799..e5349e8 100644
--- a/MVVMCrud/maui_net7/MVVMCrud.Example/ViewModels/Post/PostPageViewModel.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud.Example/ViewModels/Post/PostPageViewModel.cs
@@ -17,10 +17,7 @@ public PostPageViewModel(
{
}
- public override string SetupEndpoint()
- {
- return Constants.Constants.METHOD_POST;
- }
+ public override string SetupEndpoint() => Constants.Constants.METHOD_POST;
public override async void AddNewItem(PostItem item)
{
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudCollectionView.cs b/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudCollectionView.cs
index 7b2529d..abd3e16 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudCollectionView.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudCollectionView.cs
@@ -1,5 +1,7 @@
using System.Threading.Tasks;
using System.Windows.Input;
+using CommunityToolkit.Mvvm.Messaging;
+using DryIoc;
using MVVMCrud.ViewModels.Base;
@@ -20,22 +22,51 @@ public MVVMCrudCollectionView()
SetBinding(FooterProperty, new Binding() { Path = "LoadingMoreView" });
SetBinding(ItemsSourceProperty, new Binding() { Path = "ItemsSource" });
- var message = string.Format("ListView_OnScrool {0}", uuid);
- MessagingCenter.Subscribe(this, message, async (sender, args) =>
+ //var message = string.Format("ListView_OnScrool {0}", uuid);
+ //MessagingCenter.Subscribe(this, message, async (sender, args) =>
+ //{
+ // if (args != null)
+ // {
+ // ScrollTo(args.Item, -1, ScrollToPosition.Center);
+ // await Task.Delay(300);
+
+ // if (args.IsAnimate)
+ // {
+ // var message2 = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
+ // MessagingCenter.Send(this as object, message2, args);
+ // }
+
+ // }
+
+ //});
+
+ // Register a message in some module
+ WeakReferenceMessenger.Default.Register(this, async (r, m) =>
{
- if (args != null)
+ if (
+ m?.Value != null
+ &&
+ m?.Uuid == uuid
+ )
{
- ScrollTo(args.Item, -1, ScrollToPosition.Center);
- await Task.Delay(300);
+ var scroolTo = m.Value;
+ var item = scroolTo.Item;
- if (args.IsAnimate)
+ ScrollTo(item, -1, ScrollToPosition.Center);
+ if (scroolTo.IsAnimate)
{
- var message2 = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
- MessagingCenter.Send(this as object, message2, args);
+ await Task.Delay(500);
+
+ //var message3 = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
+ //MessagingCenter.Send(this as object, message3, args);
+
+ // Send a message from some other module
+ WeakReferenceMessenger.Default.Send(new ListViewScroolToItemAnimateMessage(uuid, item));
+
}
}
-
+
});
}
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudListView.cs b/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudListView.cs
index 1813957..611bb8a 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudListView.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudListView.cs
@@ -1,8 +1,9 @@
using System.Threading.Tasks;
using System.Windows.Input;
+using CommunityToolkit.Mvvm.Messaging;
+using DryIoc;
using MVVMCrud.ViewModels.Base;
-
namespace MVVMCrud.Controls
{
public class MVVMCrudListView : ListView
@@ -29,28 +30,87 @@ public MVVMCrudListView(ListViewCachingStrategy strategy) : base(strategy)
ItemAppearing += (sender, e) =>
{
- var message = string.Format("ListView_ItemAppearing {0}", uuid);
- MessagingCenter.Send(this as object, message, e.Item);
+ //var message = string.Format("ListView_ItemAppearing {0}", uuid);
+ //MessagingCenter.Send(this as object, message, e.Item);
+ // Send a message from some other module
+ WeakReferenceMessenger.Default.Send(new ListViewItemAppearingChangeMessage(uuid, e.Item));
};
- var message2 = string.Format("ListView_OnScrool {0}", uuid);
- MessagingCenter.Subscribe(this, message2, async (sender, args) =>
+ //var message2 = string.Format("ListView_OnScrool {0}", uuid);
+ //MessagingCenter.Subscribe(this, message2, async (sender, args) =>
+ //{
+ // if (args != null)
+ // {
+ // ScrollTo(args.Item, ScrollToPosition.Center, true);
+ // if (args.IsAnimate)
+ // {
+ // await Task.Delay(600);
+ // var message3 = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
+ // MessagingCenter.Send(this as object, message3, args);
+
+ // }
+
+ // }
+ //});
+
+ // Register a message in some module
+ WeakReferenceMessenger.Default.Register(this, async (r, m) =>
{
- if (args != null)
+ if (
+ m?.Value != null
+ &&
+ m?.Uuid == uuid
+ )
{
- ScrollTo(args.Item, ScrollToPosition.Center, true);
- if (args.IsAnimate)
+ var scroolTo = m.Value;
+ var item = scroolTo.Item;
+
+ ScrollTo(item, ScrollToPosition.Center, true);
+ if (scroolTo.IsAnimate)
{
- await Task.Delay(600);
- var message3 = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
- MessagingCenter.Send(this as object, message3, args);
+ await Task.Delay(500);
+
+ //var message3 = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
+ //MessagingCenter.Send(this as object, message3, args);
+
+ // Send a message from some other module
+ WeakReferenceMessenger.Default.Send(new ListViewScroolToItemAnimateMessage(uuid, item));
}
}
+
});
}
}
+
+ public class ListViewItemAppearingChangeMessage : GenericUUIDChangeMessage
+ {
+ public ListViewItemAppearingChangeMessage(string uuid, object value) : base(uuid, value)
+ {
+ }
+ }
+
+ public class ListViewScroolToMessage : GenericUUIDChangeMessage
+ {
+ public ListViewScroolToMessage(string uuid, ScroolToItem value) : base(uuid, value)
+ {
+ }
+ }
+
+ public class ListViewScroolToItemAnimateMessage : GenericUUIDChangeMessage
+ {
+ public ListViewScroolToItemAnimateMessage(string uuid, object value) : base(uuid, value)
+ {
+ }
+ }
+
+ public class ListViewScroolToItemAnimateToViewModelMessage : GenericUUIDChangeMessage
+ {
+ public ListViewScroolToItemAnimateToViewModelMessage(string uuid, ContentView value) : base(uuid, value)
+ {
+ }
+ }
}
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudSearchBar.cs b/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudSearchBar.cs
index 307b1ca..bc6fc81 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudSearchBar.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Controls/MVVMCrudSearchBar.cs
@@ -1,5 +1,7 @@
+using CommunityToolkit.Mvvm.Messaging;
+
namespace MVVMCrud.Controls
{
public class MVVMCrudSearchBar : SearchBar
@@ -14,9 +16,19 @@ public MVVMCrudSearchBar()
Focused += (object sender, FocusEventArgs e) =>
{
- var message = string.Format("SearchBar_Focused {0}", uuid);
- MessagingCenter.Send(this as object, message, e.IsFocused);
+ //var message = string.Format("SearchBar_Focused {0}", uuid);
+ //MessagingCenter.Send(this as object, message, e.IsFocused);
+
+ // Send a message from some other module
+ WeakReferenceMessenger.Default.Send(new SearchBarFocusedMessage(uuid, e.IsFocused));
};
}
}
+
+ public class SearchBarFocusedMessage : GenericUUIDChangeMessage
+ {
+ public SearchBarFocusedMessage(string uuid, bool isFocused) : base(uuid, isFocused)
+ {
+ }
+ }
}
diff --git a/MVVMCrud/maui_net7/MVVMCrud/MVVMCrud.csproj b/MVVMCrud/maui_net7/MVVMCrud/MVVMCrud.csproj
index bfaa6a2..07a31b5 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/MVVMCrud.csproj
+++ b/MVVMCrud/maui_net7/MVVMCrud/MVVMCrud.csproj
@@ -17,6 +17,11 @@
6.5
+
+ true
+ pdbonly
+ 4
+
ResXFileCodeGenerator
@@ -35,24 +40,14 @@
AppResources.it.resx
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
+
diff --git a/MVVMCrud/maui_net7/MVVMCrud/MVVMCrudApplication.cs b/MVVMCrud/maui_net7/MVVMCrud/MVVMCrudApplication.cs
index 62ffe35..43e7576 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/MVVMCrudApplication.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/MVVMCrudApplication.cs
@@ -1,26 +1,26 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
-using System.Net.Http;
+using System.Net.Http;
using System.Net.Http.Headers;
using System.Resources;
using MVVMCrud.CustomView;
-using MVVMCrud.Models.ItemRoot;
-using MVVMCrud.Services.Request;
-using MVVMCrud.Services.RequestProvider;
+using MVVMCrud.Models.ItemRoot;
+using MVVMCrud.Services.Request;
+using MVVMCrud.Services.RequestProvider;
using MVVMCrud.Utils;
using MVVMCrud.Utils.Request;
using MVVMCrud.Views;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Prism.Ioc;
+using CommunityToolkit.Mvvm.Messaging.Messages;
namespace MVVMCrud
{
public class MVVMCrudApplication
{
- public const string PAGINATION_RESULT_NAME = "results";
- public const string RESULT_LIST = "results";
+ public string RESULT_LIST { get; set; }
#region EmptyView
public ContentView EmptyView { get; set; }
@@ -31,7 +31,7 @@ public class MVVMCrudApplication
#endregion
#region AppResource Host App
- public ResourceManager AppResourceManager { get; set; }
+ public ResourceManager AppResourceManager { get; }
#endregion
#region Message resources
@@ -67,9 +67,13 @@ public MVVMCrudApplication()
IdMessagingCenterActiveList = new List();
+ AppResourceManager = SetupAppResourceManager();
+ RESULT_LIST = SetupResultKeyJSON();
HttpClient = SetupHttpClient();
}
+ public virtual ResourceManager SetupAppResourceManager() => AppResources.ResourceManager;
+
public virtual HttpClient SetupHttpClient() => new HttpClient();
public static string GetConfirmDeleteText() => Instance?.ConfirmDeleteText != null ? Instance.ConfirmDeleteText : AppResources.msg_confirm_delete;
@@ -96,18 +100,23 @@ public MVVMCrudApplication()
public static ContentView GetLoadingMoreView() => Instance?.LoadingMoreView != null ? Instance.LoadingMoreView : new LoadingMoreView();
public static ResourceManager GetAppResourceManager() => Instance?.AppResourceManager != null ? Instance.AppResourceManager : AppResources.ResourceManager;
+ public static string GetResultKeyJSON() => Instance?.RESULT_LIST != null ? "results" : Instance.SetupResultKeyJSON();
+
public virtual BaseRequestSetupResponse SetupBaseRequestSetupResponse() => new BaseRequestSetupResponse();
- public virtual List GetJsonConverters()
- {
- var l = new List
+ public virtual List GetJsonConverters()
+ {
+ var l = new List
{
};
return l;
}
+
+ public virtual string SetupResultKeyJSON() => "results";
+
public virtual void SetupPaginationItem(string item, HttpResponseHeaders responseHeader, PaginationItem paginationItem){}
public virtual void SetupRootItemBase(RootItemBase rootItemBase){}
@@ -119,42 +128,42 @@ public virtual void SetupPaginationRequest(List> da
int paginationSize)
{ }
- public virtual JsonSerializerSettings SetupJsonSettingsSerialize(bool ignoreJsonProperty = true)
+ public virtual JsonSerializerSettings SetupJsonSettingsSerialize(bool ignoreJsonProperty = true)
{
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
};
-
- if (ignoreJsonProperty)
- {
- settings.ContractResolver = new IgnoreJsonPropertyContractResolver();
- }
-
- settings.Converters = GetJsonConverters();
-
+
+ if (ignoreJsonProperty)
+ {
+ settings.ContractResolver = new IgnoreJsonPropertyContractResolver();
+ }
+
+ settings.Converters = GetJsonConverters();
+
return settings;
}
-
- public virtual JsonSerializerSettings SetupJsonSettingsDeserialize(bool ignoreJsonProperty=false)
+
+ public virtual JsonSerializerSettings SetupJsonSettingsDeserialize(bool ignoreJsonProperty=false)
{
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new IgnoreJsonPropertyContractResolver()
};
-
- if (ignoreJsonProperty)
- {
- settings.ContractResolver = new IgnoreJsonPropertyContractResolver();
- }
-
- settings.Converters = GetJsonConverters();
-
- return settings;
- }
-
+
+ if (ignoreJsonProperty)
+ {
+ settings.ContractResolver = new IgnoreJsonPropertyContractResolver();
+ }
+
+ settings.Converters = GetJsonConverters();
+
+ return settings;
+ }
+
public virtual JsonSerializerSettings SetupJsonUploadSettingsSerialize()
{
var settings = new JsonSerializerSettings
@@ -163,7 +172,7 @@ public virtual JsonSerializerSettings SetupJsonUploadSettingsSerialize()
};
return settings;
- }
+ }
public static void RegisterServices(IContainerRegistry containerRegistry)
{
@@ -188,4 +197,14 @@ public static string GetLastPageUUID()
}
}
-}
+ public class GenericUUIDChangeMessage : ValueChangedMessage
+ {
+ public string Uuid { get; private set; }
+
+ public GenericUUIDChangeMessage(string uuid, T value) : base(value)
+ {
+ Uuid = uuid;
+ }
+ }
+
+}
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Models/Base/BaseModelRoot.cs b/MVVMCrud/maui_net7/MVVMCrud/Models/Base/BaseModelRoot.cs
index 297d86a..5d85d33 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Models/Base/BaseModelRoot.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Models/Base/BaseModelRoot.cs
@@ -209,7 +209,7 @@ void ProcessWithPagination(string response, HttpStatusCode httpStatus, HttpRespo
if (!RootItemBase.IsError)
{
- var itemsArray = item.GetValue(MVVMCrudApplication.PAGINATION_RESULT_NAME).ToObject();
+ var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject();
PaginationItem = new PaginationItem(response, responseHeader);
OnDataArray(itemsArray);
@@ -236,7 +236,7 @@ void ProcessWithPaginationExtraData(string response, HttpStatusCode httpStatus,
if (!RootItemBase.IsError)
{
- var itemsArray = item.GetValue(MVVMCrudApplication.PAGINATION_RESULT_NAME).ToObject();
+ var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject();
PaginationItem = new PaginationItem(response, responseHeader);
OnDataObject(item);
@@ -252,7 +252,7 @@ void ProcessWithoutPaginationExtraData(string response, HttpStatusCode httpStatu
if (!RootItemBase.IsError)
{
- var itemsArray = item.GetValue(MVVMCrudApplication.RESULT_LIST).ToObject();
+ var itemsArray = item.GetValue(MVVMCrudApplication.GetResultKeyJSON()).ToObject();
OnDataObject(item);
OnDataArray(itemsArray);
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Services/Request/IRequestService.cs b/MVVMCrud/maui_net7/MVVMCrud/Services/Request/IRequestService.cs
index 557d7f2..dbe609c 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Services/Request/IRequestService.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Services/Request/IRequestService.cs
@@ -87,7 +87,8 @@ Task RequestDefaultCreateUpdateItem
bool getIfError = false,
bool showLoading = true,
List httpStatusCodes = null,
- Action setupItem = null)
+ Action setupItem = null,
+ bool partialUpdate = false)
where TItemRoot : BaseModelItemRoot, new()
where TItem : BaseItem, new();
@@ -140,7 +141,8 @@ Task CreateUpdate
string pk = null,
MultipartFormDataContent formData = null,
HttpContent httpContent = null,
- HttpClient httpClient = null)
+ HttpClient httpClient = null,
+ bool partialUpdate = false)
where TItemRoot : BaseModelItemRoot, new()
where TItem : BaseItem, new();
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Services/Request/RequestService.cs b/MVVMCrud/maui_net7/MVVMCrud/Services/Request/RequestService.cs
index 39f66fc..43d6a55 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Services/Request/RequestService.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Services/Request/RequestService.cs
@@ -221,7 +221,8 @@ public async Task RequestDefaultCreateUpdateItem
bool getIfError = false,
bool showLoading = true,
List httpStatusCodes = null,
- Action setupItem = null)
+ Action setupItem = null,
+ bool partialUpdate = false)
where TItemRoot : BaseModelItemRoot, new()
where TItem : BaseItem, new()
@@ -237,7 +238,7 @@ public async Task RequestDefaultCreateUpdateItem
return await RequestItem(
async () =>
{
- return await CreateUpdate(url, pk, formDataContent, httpContent, httpClient);
+ return await CreateUpdate(url, pk, formDataContent, httpContent, httpClient, partialUpdate);
}, title, getIfError, showLoading, httpCodes, setupItem);
}
@@ -377,7 +378,8 @@ public async Task CreateUpdate
string pk = null,
MultipartFormDataContent formData = null,
HttpContent httpContent = null,
- HttpClient httpClient = null)
+ HttpClient httpClient = null,
+ bool partialUpdate = false)
where TItemRoot : BaseModelItemRoot, new()
where TItem : BaseItem, new()
@@ -405,7 +407,7 @@ public async Task CreateUpdate
}
else
{
- respondData = await _requestProvider.PutAsync(apiUrl, formData, httpClient);
+ respondData = await _requestProvider.PutAsync(apiUrl, formData, httpClient, partialUpdate);
}
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/IRequestProvider.cs b/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/IRequestProvider.cs
index 7bc4f8f..54989db 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/IRequestProvider.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/IRequestProvider.cs
@@ -12,7 +12,7 @@ public interface IRequestProvider
Task PostMultipartFormAsync(string apiUrl, MultipartFormDataContent data = null, HttpClient httpClient = null);
Task GetAsync(string apiUrl, HttpClient httpClient = null, FormUrlEncodedContent content_query = null);
Task GetAsyncPagination(string apiUrl, HttpClient httpClient = null, string urlPagination = null, bool pagination = true, FormUrlEncodedContent content_query = null, int paginationSize = 0, string string_query = null, Action>, bool, int> paginationRequest = null);
- Task PutAsync(string apiUrl, HttpContent data = null, HttpClient httpClient = null);
+ Task PutAsync(string apiUrl, HttpContent data = null, HttpClient httpClient = null, bool partialUpdate = false);
Task DeleteAsync(string apiUrl, HttpClient httpClient = null);
Task GetByteArray(string apiUrl, HttpClient httpClient = null, bool header = true);
}
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/RequestProvider.cs b/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/RequestProvider.cs
index 7d63c0b..502c523 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/RequestProvider.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Services/RequestProvider/RequestProvider.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
+using System.Reflection.PortableExecutable;
using System.Threading.Tasks;
using MVVMCrud.Models.RequestResponse;
@@ -273,11 +274,21 @@ public async Task DeleteAsync(string apiUrl, HttpClient htt
}
- public async Task PutAsync(string apiUrl, HttpContent data = null, HttpClient httpClient = null)
+ public async Task PutAsync(string apiUrl, HttpContent data = null, HttpClient httpClient = null, bool partialUpdate = false)
{
- System.Diagnostics.Debug.WriteLine("\nMVVMCrud PutAsync");
+
+
+ System.Diagnostics.Debug.WriteLine("\nPutAsync");
System.Diagnostics.Debug.WriteLine("PutAsync apiUrl = " + apiUrl);
- System.Diagnostics.Debug.WriteLine("PutAsync data = " + data);
+ System.Diagnostics.Debug.WriteLine("PutAsync partialUpdate = " + partialUpdate);
+
+ if (data != null)
+ {
+ System.Diagnostics.Debug.WriteLine("PutAsync data = " + await data?.ReadAsStringAsync());
+ }
+
+ System.Diagnostics.Debug.WriteLine("PutAsync HttpClient = " + httpClient);
+
RequestResponseItem responseItem = null;
@@ -289,11 +300,25 @@ public async Task PutAsync(string apiUrl, HttpContent data
try
{
- var response = await client.PutAsync(apiUrl, data);
+ HttpResponseMessage response = null;
- string json = await response.Content.ReadAsStringAsync();
- var responseStatus = response.StatusCode;
+ if (!partialUpdate)
+ {
+ response = await client.PutAsync(apiUrl, data);
+ }
+ else
+ {
+ //https://stackoverflow.com/questions/47463000/c-sharp-xamarin-forms-add-custom-header-patch
+ var method = new HttpMethod("PATCH");
+ var request = new HttpRequestMessage(method, apiUrl)
+ {
+ Content = data
+ };
+ response = await client.SendAsync(request);
+ }
+ var json = await response.Content.ReadAsStringAsync();
+ var responseStatus = response.StatusCode;
responseItem = new RequestResponseItem(responseStatus, json, response.Headers);
@@ -302,8 +327,6 @@ public async Task PutAsync(string apiUrl, HttpContent data
}
catch (Exception e)
{
-
-
System.Diagnostics.Debug.WriteLine("PutAsync Exception = " + e.ToString());
System.Diagnostics.Debug.WriteLine("httpcode = null");
System.Diagnostics.Debug.WriteLine("response = " + e.ToString());
@@ -317,7 +340,6 @@ public async Task PutAsync(string apiUrl, HttpContent data
return responseItem;
}
-
public async Task GetByteArray(string apiUrl, HttpClient httpClient = null, bool header = true)
{
System.Diagnostics.Debug.WriteLine("\nMVVMCrud GetByteArray");
diff --git a/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseItemEditAdvancedViewModel.cs b/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseItemEditAdvancedViewModel.cs
index 090c5cd..14ce6e3 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseItemEditAdvancedViewModel.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseItemEditAdvancedViewModel.cs
@@ -332,14 +332,25 @@ public virtual async Task SetupRequest(TItemInput item)
public virtual async void SetupReturnItem(TItem item)
{
- var navParams = new NavigationParameters
- {
- { "newEditItem", new NewEditItem(item, Position, Section) }
- };
+ var navParams = SetupReturnItemParams(item);
- var navResult = await NavigationService.GoBackAsync(parameters: navParams);
+ var navResult = await SetupReturnNavigation(navParams, item);
+ }
+
+ public virtual async Task SetupReturnNavigation(NavigationParameters navParams, TItem item)
+ {
+ return await NavigationService.GoBackAsync(parameters: navParams);
}
+ public virtual NewEditItem SetupReturnItemRawParams(TItem item) => new NewEditItem(item, Position, Section);
+
+ public virtual NavigationParameters SetupReturnItemParams(TItem item)
+ {
+ return new NavigationParameters
+ {
+ { "newEditItem", SetupReturnItemRawParams(item) }
+ };
+ }
}
public class NewEditItem
diff --git a/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedHeaderViewModel.cs b/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedHeaderViewModel.cs
index ff69cde..be6c4f1 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedHeaderViewModel.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedHeaderViewModel.cs
@@ -220,30 +220,42 @@ THeaderCellVM InstanceHeaderCellVM(THeaderItem item)
public virtual async void SetupHeaderEditItem(THeaderCellVM cellVM)
{
- var navParams = new NavigationParameters
- {
- { "position", HeaderPosition },
- { "endpoint", HeaderEndpoint },
- { "itemSerialized", SetupHeaderCreateUpdatePageItemSerialized(cellVM) },
- };
+ var page = SetupHeaderCreateUpdatePage(cellVM);
+ var navParams = SetupHeaderEditItemNavParams(cellVM);
+ var useModalNavigation = SetupHeaderCreateUpdatePageIsModal(cellVM);
- var page = SetupHeaderCreateUpdatePage();
- if (!string.IsNullOrWhiteSpace(page))
- {
- //var navResult = await NavigationService.NavigateAsync(page, navParams, useModalNavigation: SetupCreateUpdatePageIsModal());
- var navResult = await NavigationService.NavigateAsync(page, navParams);
- }
+ var navResult = await SetupHeaderNavigationPage(page, navParams, cellVM, useModalNavigation);
+ }
+ public virtual bool SetupHeaderCreateUpdatePageIsModal(THeaderCellVM cellVM)
+ {
+ return base.SetupCreateUpdatePageIsModal();
}
- public virtual string SetupHeaderCreateUpdatePageName()
+ public virtual async Task SetupHeaderNavigationPage(string page, INavigationParameters navParams, THeaderCellVM cellVM = null, bool useModalNavigation = false)
+ {
+ return await NavigationService.NavigateAsync(page, navParams);
+ //return await NavigationService.NavigateAsync(page, navParams, useModalNavigation: useModalNavigation);
+ }
+
+ public virtual string SetupHeaderCreateUpdatePageName(THeaderCellVM cellVM)
{
return FromPagelViewModelName;
}
- public virtual string SetupHeaderCreateUpdatePage()
+ public virtual NavigationParameters SetupHeaderEditItemNavParams(THeaderCellVM cellVM)
+ {
+ return new NavigationParameters
+ {
+ { "position", HeaderPosition },
+ { "endpoint", HeaderEndpoint },
+ { "itemSerialized", SetupHeaderCreateUpdatePageItemSerialized(cellVM) },
+ };
+ }
+
+ public virtual string SetupHeaderCreateUpdatePage(THeaderCellVM cellVM)
{
- var pageVMName = SetupHeaderCreateUpdatePageName();
+ var pageVMName = SetupHeaderCreateUpdatePageName(cellVM);
var pageContext = pageVMName.Split(new[] { "PageViewModel" }, StringSplitOptions.None);
if (pageContext?.Length == 2)
@@ -350,6 +362,7 @@ public override void OnNavigatedTo(INavigationParameters parameters)
}
}
}
+
}
public virtual void UpdateEditHeaderItem(NewEditItem editHeaderItem)
diff --git a/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedViewModel.cs b/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedViewModel.cs
index 379f66c..e1db0b7 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedViewModel.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/ViewModels/Base/BaseListPaginationAdvancedViewModel.cs
@@ -4,6 +4,8 @@
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
+using CommunityToolkit.Mvvm.Messaging;
+using MVVMCrud.Controls;
using MVVMCrud.CustomView;
using MVVMCrud.Models.Base;
using MVVMCrud.Models.ItemRoot;
@@ -41,6 +43,8 @@ public override void Initialize(INavigationParameters parameters)
{
base.Initialize(parameters);
+ SubscribeMessagingCenter();
+
TitlePage = SetupTitlePage();
Endpoint = SetupEndpoint();
@@ -50,10 +54,6 @@ public override void Initialize(INavigationParameters parameters)
{
_ = SetupGet();
}
- else
- {
- ShowMessage(MVVMCrudApplication.GetLoadingText());
- }
}
@@ -337,21 +337,24 @@ public virtual string GetCancelText()
public virtual async void SetupEditItem(TCellVM cellVM)
{
- var navParams = new NavigationParameters
+ var page = SetupCreateUpdatePage();
+ var navParams = SetupEditItemNavParams(cellVM);
+ var useModalNavigation = SetupCreateUpdatePageIsModal();
+
+ var navResult = await SetupNavigationPage(page, navParams, cellVM, useModalNavigation);
+ }
+
+ public virtual NavigationParameters SetupEditItemNavParams(TCellVM cellVM)
+ {
+ return new NavigationParameters
{
{ "endpoint", SetupCreateUpdatePageEndpoint() },
{ "itemSerialized", SetupCreateUpdatePageItemSerialized(cellVM) },
{ "position", ItemsList.IndexOf(cellVM) }
};
-
- var page = SetupCreateUpdatePage();
- if (!string.IsNullOrWhiteSpace(page))
- {
- //var navResult = await NavigationService.NavigateAsync(page, navParams, useModalNavigation: SetupCreateUpdatePageIsModal());
- var navResult = await NavigationService.NavigateAsync(page, navParams);
- }
}
+
public virtual string SetupCreateUpdatePageItemSerialized(TCellVM cellVM)
{
var item = cellVM.Item;
@@ -368,28 +371,47 @@ public virtual string SetupCreateUpdatePageItemSerialized(TCellVM cellVM)
public override async void TlbAddClick()
{
+ //var result = await NavigationService.CreateBuilder()
+ // .UseAbsoluteNavigation(SetupCreateUpdatePageIsModal())
+ // .AddSegment(nameof(MVVMCrudModalNavigationPage))
+ // .AddSegment(page, SetupCreateUpdatePageIsModal())
+ // .WithParameters(navParams)
+ // .NavigateAsync();
+
+ //if (SetupCreateUpdatePageIsModal())
+ //{
+ // navParams.Add(KnownNavigationParameters.UseModalNavigation, true);
+ //}
+
+ var navParams = SetupCreateNavParams();
var page = SetupCreateUpdatePage();
- if (!string.IsNullOrWhiteSpace(page))
+ var useModalNavigation = SetupCreateUpdatePageIsModal();
+ var navResult = await SetupNavigationPage(page, navParams, useModalNavigation: useModalNavigation);
+ }
+
+ public virtual NavigationParameters SetupCreateNavParams()
+ {
+ return new NavigationParameters
{
- var navParams = new NavigationParameters
- {
- { "endpoint", SetupCreateUpdatePageEndpoint() },
- };
+ { "endpoint", SetupCreateUpdatePageEndpoint() },
+ };
+ }
- //var navResult = await NavigationService.NavigateAsync(page, navParams, useModalNavigation: SetupCreateUpdatePageIsModal());
- var navResult = await NavigationService.NavigateAsync(page, navParams);
- }
+ public virtual async Task SetupNavigationPage(string page, INavigationParameters navParams, TCellVM cellVM = null, bool useModalNavigation = false)
+ {
+ return await NavigationService.NavigateAsync(page, navParams);
+ //return await NavigationService.NavigateAsync(page, navParams, useModalNavigation: useModalNavigation);
}
- public virtual string SetupCreateUpdatePageName()
+ public virtual string SetupCreateUpdatePageName(TCellVM cellVM = null)
{
return GetType().Name;
}
- public virtual string SetupCreateUpdatePage()
+ public virtual string SetupCreateUpdatePage(TCellVM cellVM = null)
{
- var pageVMName = SetupCreateUpdatePageName();
+ var pageVMName = SetupCreateUpdatePageName(cellVM);
var pageContext = pageVMName.Split(new[] { "PageViewModel" }, StringSplitOptions.None);
if (pageContext?.Length == 2)
@@ -400,14 +422,14 @@ public virtual string SetupCreateUpdatePage()
return pageNewEdit;
- if (!SetupCreateUpdatePageIsModal())
- {
- return pageNewEdit;
- }
- else
- {
- return string.Format("{0}/{1}", nameof(MVVMCrudModalNavigationPage), pageNewEdit);
- }
+ //if (!SetupCreateUpdatePageIsModal(cellVM)
+ //{
+ // return pageNewEdit;
+ //}
+ //else
+ //{
+ // return string.Format("{0}/{1}", nameof(MVVMCrudModalNavigationPage), pageNewEdit);
+ //}
}
@@ -415,7 +437,7 @@ public virtual string SetupCreateUpdatePage()
return null;
}
- public virtual bool SetupCreateUpdatePageIsModal()
+ public virtual bool SetupCreateUpdatePageIsModal(TCellVM cellVM = null)
{
if (DeviceInfo.Platform == DevicePlatform.iOS)
{
@@ -530,11 +552,14 @@ public virtual bool IsDetailPageModal(TCellVM obj)
public virtual async void SetupDetailPage(TCellVM obj)
{
- var pageName = SetupDetailPageName(obj);
+ var navResult = await SetupNavigationPage(SetupDetailPageName(obj), SetupDetailPageNavParams(obj), obj, IsDetailPageModal(obj));
+ }
+
+ public virtual NavigationParameters SetupDetailPageNavParams(TCellVM obj)
+ {
var withHeader = IsDetailPageWithHeader(obj);
var id = SetupDetailPageID(obj);
- var modal = IsDetailPageModal(obj);
-
+
var position = ItemsSource.IndexOf(obj);
var fromPageName = GetType().Name;
@@ -554,20 +579,10 @@ public virtual async void SetupDetailPage(TCellVM obj)
navParams.Add("id", id);
}
- modal = false;
- if (!modal)
- {
- var navResult = await NavigationService.NavigateAsync(pageName, navParams);
- }
- else
- {
- pageName = nameof(MVVMCrudModalNavigationPage) + "/" + pageName;
- //var navResult = await NavigationService.NavigateAsync(pageName, navParams, useModalNavigation=modal);
- }
-
-
+ return navParams;
}
+
public override void PerformSearch(string newText)
{
if (
@@ -627,58 +642,107 @@ public override void PerformSearch(string newText)
public virtual void SubscribeListViewItemAppearing()
{
- var message = string.Format("ListView_ItemAppearing {0}", _uuidMessagingCenter);
- MessagingCenter.Subscribe(this, message, (sender, args) =>
+ //var message = string.Format("ListView_ItemAppearing {0}", _uuidMessagingCenter);
+ //MessagingCenter.Subscribe(this, message, (sender, args) =>
+ //{
+ // if (
+ // ItemsList != null
+ // &&
+ // ItemsList.Count > 0
+ // &&
+ // args == ItemsList[ItemsList.Count - 1]
+ // )
+ // {
+ // ItemsThresholdReached();
+ // }
+
+ //});
+
+ // Register a message in some module
+ WeakReferenceMessenger.Default.Register(this, (r, m) =>
{
if (
- ItemsList != null
- &&
- ItemsList.Count > 0
- &&
- args == ItemsList[ItemsList.Count - 1]
- )
+ ItemsList != null
+ &&
+ ItemsList.Count > 0
+ &&
+ m?.Uuid == _uuidMessagingCenter
+ &&
+ m?.Value == ItemsList[ItemsList.Count - 1]
+ )
{
ItemsThresholdReached();
}
-
});
}
public virtual void SubscribeSearchBarFocused()
{
- var message = string.Format("SearchBar_Focused {0}", _uuidMessagingCenter);
- MessagingCenter.Subscribe(this, message, (sender, isFocused) =>
+ //var message = string.Format("SearchBar_Focused {0}", _uuidMessagingCenter);
+ //MessagingCenter.Subscribe(this, message, (sender, isFocused) =>
+ //{
+ // SearchBarFocused(isFocused);
+ //});
+
+ // Register a message in some module
+ WeakReferenceMessenger.Default.Register(this, (r, m) =>
{
- SearchBarFocused(isFocused);
+ if (
+ m?.Value != null
+ &&
+ m?.Uuid == _uuidMessagingCenter
+ )
+ {
+ SearchBarFocused(m.Value);
+ }
+
});
}
public virtual void SubscribeScroolToAnimate()
{
- var message = string.Format("ListView_ScroolToItem_Animate_To_ViewModel {0}", _uuidMessagingCenter);
- MessagingCenter.Subscribe(this, message, (sender) =>
+ //var message = string.Format("ListView_ScroolToItem_Animate_To_ViewModel {0}", _uuidMessagingCenter);
+ //MessagingCenter.Subscribe(this, message, (sender) =>
+ //{
+ // ScroolToAnimate(sender);
+ //});
+
+ WeakReferenceMessenger.Default.Register(this, (r, m) =>
{
- ScroolToAnimate(sender);
+ if (
+ m?.Value != null
+ &&
+ m?.Uuid == _uuidMessagingCenter
+ )
+ {
+ ScroolToAnimate(m.Value);
+ }
});
}
public virtual void UnsubscribeListViewItemAppearing()
{
- var message = string.Format("ListView_ItemAppearing {0}", _uuidMessagingCenter);
- MessagingCenter.Unsubscribe(this, message);
+ //var message = string.Format("ListView_ItemAppearing {0}", _uuidMessagingCenter);
+ //MessagingCenter.Unsubscribe(this, message);
+
+ WeakReferenceMessenger.Default.Unregister(this);
}
public virtual void UnsubscribeSearchBarFocused()
{
- var message = string.Format("SearchBar_Focused {0}", _uuidMessagingCenter);
- MessagingCenter.Unsubscribe(this, message);
+ //var message = string.Format("SearchBar_Focused {0}", _uuidMessagingCenter);
+ //MessagingCenter.Unsubscribe(this, message);
+
+ WeakReferenceMessenger.Default.Unregister(this);
}
public virtual void UnsubscribeScroolToAnimate()
{
- var message = string.Format("ListView_ScroolToItem_Animate_To_ViewModel {0}", _uuidMessagingCenter);
- MessagingCenter.Unsubscribe(this, message);
+ //var message = string.Format("ListView_ScroolToItem_Animate_To_ViewModel {0}", _uuidMessagingCenter);
+ //MessagingCenter.Unsubscribe(this, message);
+
+ WeakReferenceMessenger.Default.Unregister(this);
}
public virtual void SubscribeMessagingCenter()
@@ -711,32 +775,30 @@ public override void OnNavigatedTo(INavigationParameters parameters)
{
base.OnNavigatedTo(parameters);
- SubscribeMessagingCenter();
-
- if (parameters.ContainsKey("newEditItem"))
+ if (parameters.ContainsKey("deleteItem"))
{
- var newEditItem = parameters["newEditItem"] as NewEditItem;
- if (newEditItem != null)
- {
- var pos = newEditItem.Position;
- if (pos == -1)
- {
- //New
- AddNewItem(newEditItem.Item);
- }
- else
- {
- //Edit
- UpdateEditItem(newEditItem);
- }
- }
+ var pos = parameters.GetValue("deleteItem");
+ SetupDeleteItem(pos);
}
else
{
- if (parameters.ContainsKey("deleteItem"))
+ if (parameters.ContainsKey("newEditItem"))
{
- var pos = parameters.GetValue("deleteItem");
- SetupDeleteItem(pos);
+ var newEditItem = parameters["newEditItem"] as NewEditItem;
+ if (newEditItem != null)
+ {
+ var pos = newEditItem.Position;
+ if (pos == -1)
+ {
+ //New
+ AddNewItem(newEditItem.Item);
+ }
+ else
+ {
+ //Edit
+ UpdateEditItem(newEditItem);
+ }
+ }
}
}
}
@@ -745,7 +807,11 @@ public override void OnNavigatedFrom(INavigationParameters parameters)
{
base.OnNavigatedFrom(parameters);
- UnsubscribeMessagingCenter();
+ if (parameters.GetNavigationMode() == Prism.Navigation.NavigationMode.Back)
+ {
+ UnsubscribeMessagingCenter();
+ }
+
}
public virtual int AddNewItemPosition() => 0;
@@ -794,8 +860,11 @@ public virtual void ScroolTo(object listObj)
Item = listObj
};
- var message = string.Format("ListView_OnScrool {0}", _uuidMessagingCenter);
- MessagingCenter.Send(this as object, message, scroolToItem);
+ //var message = string.Format("ListView_OnScrool {0}", _uuidMessagingCenter);
+ //MessagingCenter.Send(this as object, message, scroolToItem);
+
+ // Send a message from some other module
+ WeakReferenceMessenger.Default.Send(new ListViewScroolToMessage(_uuidMessagingCenter, scroolToItem));
}
public virtual bool ScroolToAnimateIsEnable()
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentPage.cs b/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentPage.cs
index bdc50dd..1ed339c 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentPage.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentPage.cs
@@ -18,24 +18,11 @@ public BaseContentPage()
SetBinding(TitleProperty, new Binding() { Path = "TitlePage" });
}
- protected override void OnAppearing()
- {
- base.OnAppearing();
-
- MessagingCenter.Send(this as ContentPage, "Page_OnAppearing");
- }
-
protected override void OnDisappearing()
{
base.OnDisappearing();
MVVMCrudApplication.Instance?.IdMessagingCenterActiveList.Remove(_uuid);
-
- MessagingCenter.Send(this as ContentPage, "Page_OnDisappearing");
-
- System.Diagnostics.Debug.WriteLine("disappearing");
-
-
}
}
}
diff --git a/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentView.cs b/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentView.cs
index c0fd6d3..21f68ec 100644
--- a/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentView.cs
+++ b/MVVMCrud/maui_net7/MVVMCrud/Views/Base/BaseContentView.cs
@@ -1,4 +1,8 @@
-using MVVMCrud;
+using System.Diagnostics;
+using CommunityToolkit.Mvvm.Messaging;
+using DryIoc;
+using MVVMCrud;
+using MVVMCrud.Controls;
using MVVMCrud.ViewModels.Base;
using Newtonsoft.Json;
@@ -11,23 +15,43 @@ public BaseContentView()
this.SetDynamicResource(ContentView.BackgroundColorProperty, "cellBackgroundColor");
var uuid = MVVMCrudApplication.GetLastPageUUID();
- var message = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
- MessagingCenter.Subscribe(this, message, (sender, args) =>
+
+ //var message = string.Format("ListView_ScroolToItemAnimate {0}", uuid);
+ //MessagingCenter.Subscribe(this, message, (sender, args) =>
+ //{
+ // try
+ // {
+ // if (
+ // args != null
+ // &&
+ // JsonConvert.SerializeObject(BindingContext).Equals(JsonConvert.SerializeObject(args.Item))
+ // )
+ // {
+ // var message2 = string.Format("ListView_ScroolToItem_Animate_To_ViewModel {0}", uuid);
+ // MessagingCenter.Send(this as ContentView, message2);
+ // }
+ // }
+ // catch (System.Exception) { }
+
+ //});
+
+
+ // Register a message in some module
+ WeakReferenceMessenger.Default.Register(this, (r, m) =>
{
try
{
if (
- args != null
+ m?.Uuid == uuid
&&
- JsonConvert.SerializeObject(BindingContext).Equals(JsonConvert.SerializeObject(args.Item))
+ JsonConvert.SerializeObject(BindingContext).Equals(JsonConvert.SerializeObject(m?.Value))
)
{
- var message2 = string.Format("ListView_ScroolToItem_Animate_To_ViewModel {0}", uuid);
- MessagingCenter.Send(this as ContentView, message2);
+ // Send a message from some other module
+ WeakReferenceMessenger.Default.Send(new ListViewScroolToItemAnimateToViewModelMessage(uuid, this));
}
}
- catch (System.Exception) { }
-
+ catch (Exception){}
});
}
}