Files
Common-VS2019/SacsMobileMaui/Maui/Pages/SamContentPage.cs
T

158 lines
4.5 KiB
C#

using Microsoft.Maui.Controls;
using Sarand.Net.Mobile.Maui.Logic;
using Sarand.Net.Mobile.Maui.Views;
using Sarand.Net.Standard.Base.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Sarand.Net.Mobile.Maui.Pages
{
//=======================================================================
public abstract class SamContentPage : ContentPage, ISamView
{
//-------------------------------------------------------------------
// Definitions.
//-------------------------------------------------------------------
// Data members.
//-------------------------------------------------------------------
// Construction.
public SamContentPage()
{
}
//-------------------------------------------------------------------
// Properties.
public abstract String MessageTitleDefault { get; }
//-------------------------------------------------------------------
// C o n f i g u r e C o m p o n e n t s
//-------------------------------------------------------------------
protected virtual void ConfigureComponents()
{
}
protected virtual void ConfigureChildComponents()
{
SamViewTreeUtil.ConfigureChildren(Content);
}
//-------------------------------------------------------------------
// C o n t r o l A c t i v i t y
//-------------------------------------------------------------------
protected virtual void SetControlActivity(bool enabled)
{
if (IsEnabled != enabled) IsEnabled = enabled;
SetControlsReadOnly();
SamViewTreeUtil.SetChildControlActivity(Content, enabled);
}
protected virtual void SetControlsReadOnly()
{
}
void ISamView.ConfigureComponents()
{
ConfigureComponents();
}
void ISamView.SetControlActivity(bool enabled)
{
SetControlActivity(enabled);
}
void ISamView.SetControlsReadOnly()
{
SetControlsReadOnly();
}
//-------------------------------------------------------------------
// P o p u p M e s s a g e s
//-------------------------------------------------------------------
public enum AlertMode
{
OK,
Close,
}
public Task DisplayAlert(String message, AlertMode alertMode = AlertMode.OK)
{
String title = StringUtil.OnEmpty(Title, MessageTitleDefault);
String cancel = "OK";
if (alertMode == AlertMode.Close)
cancel = "Close";
return DisplayAlertAsync(title, message, cancel);
}
public enum ConfirmMode
{
YesNo,
OkCancel
}
public async Task<bool> DisplayConfirm(String message, ConfirmMode confirmMode = ConfirmMode.OkCancel)
{
String title = StringUtil.OnEmpty(Title, MessageTitleDefault);
String accept = "Yes";
String cancel = "No";
if (confirmMode == ConfirmMode.OkCancel)
{
accept = "OK";
cancel = "Cancel";
}
return await DisplayAlertAsync(title, message, accept, cancel);
}
//-------------------------------------------------------------------
// P a g e E v e n t s
//-------------------------------------------------------------------
protected override void OnParentSet()
{
base.OnParentSet();
}
//-------------------------------------------------------------------
protected override void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
base.OnPropertyChanged(propertyName);
}
//-------------------------------------------------------------------
protected override void OnAppearing()
{
base.OnAppearing();
ConfigureComponents();
ConfigureChildComponents();
}
//-------------------------------------------------------------------
// Layout changes.
private bool inOnSizeAllocated = false;
protected override void OnSizeAllocated(double width, double height)
{
bool alreadyInOnSizeAllocated = inOnSizeAllocated;
inOnSizeAllocated = true;
base.OnSizeAllocated(width, height);
// Only configure components if this is the first entry to this event
// // to avoid iterative layout changes caused by components being configured.
if (!alreadyInOnSizeAllocated)
{
if (Width > 0 && Height > 0)
{
ConfigureComponents();
ConfigureChildComponents();
}
inOnSizeAllocated = false;
}
}
//-------------------------------------------------------------------
protected override void OnDisappearing()
{
base.OnDisappearing();
}
//-------------------------------------------------------------------
}
//=======================================================================
}