Class BasePage
页面基础类
Inheritance
Derived
Implements
Extension Methods
Namespace: Fleet.Mobile.Containers
Assembly: FleetMobile.dll
Syntax
public abstract class BasePage : ContentPage, INotifyPropertyChanged, IVisualTreeElement, IEffectControlProvider, IToolTipElement, IContextFlyoutElement, IAnimatable, ILayout, IPageController, IVisualElementController, IElementController, IElementConfiguration<Page>, ISafeAreaView, ITitledElement, IToolbarElement, IContentView, IPadding, ICrossPlatformLayout, IHotReloadableView, IView, IElement, ITransform, IReplaceableView, ILoading, INetworkIndicator
Constructors
BasePage()
Declaration
public BasePage()
Fields
DelayedTime
IsLoadingProperty
IsNetworkFailedProperty
Declaration
public static readonly BindableProperty IsNetworkFailedProperty
Field Value
| BindableProperty |
SafeAreaThicknessProperty
Declaration
public static readonly BindableProperty SafeAreaThicknessProperty
Field Value
| BindableProperty |
isBusy
serializerOptions
默认序列化选项,字段为默认值时不序列化
Declaration
protected static readonly JsonSerializerOptions serializerOptions
Field Value
| JsonSerializerOptions |
Properties
BackCommand
CustomHandlerViews
获取自定义视图处理器,在页面卸载时会手动断开链接
Declaration
protected virtual IEnumerable<VisualElement> CustomHandlerViews { get; }
Property Value
| IEnumerable<VisualElement> |
IsAutoRotateAllowed
IsBackButtonVisible
IsClosableWhenLoading
获取页面加载时是否可以被关闭
Declaration
protected virtual bool IsClosableWhenLoading { get; }
Property Value
| bool |
IsFleetBotVisible
IsLoading
IsNetworkFailed
MainCollectionView
获取主 CollectionView,默认点击标题区域时将滚动到首行
Declaration
protected virtual CollectionView MainCollectionView { get; }
Property Value
| CollectionView |
SafeAreaInsets
SafeAreaThickness
TitleTapCommand
Methods
AddIconToolbarItem(string, EventHandler, Command)
Declaration
protected void AddIconToolbarItem(string glyph, EventHandler handler = null, Command command = null)
Parameters
| string glyph |
| EventHandler handler |
| Command command |
AddIconToolbarItem<T>(string, Func<T, bool>, string, T, bool, EventHandler, Command)
Declaration
protected void AddIconToolbarItem<T>(string glyph, Func<T, bool> getter, string memberName, T source = default, bool isNegated = false, EventHandler handler = null, Command command = null)
Parameters
| string glyph |
| Func<T, bool> getter |
| string memberName |
| T source |
| bool isNegated |
| EventHandler handler |
| Command command |
Type Parameters
| T |
AddTextToolbarItem(string, EventHandler, Command)
Declaration
protected void AddTextToolbarItem(string text, EventHandler handler = null, Command command = null)
Parameters
| string text |
| EventHandler handler |
| Command command |
AddTextToolbarItem<T>(string, Func<T, bool>, string, T, bool, EventHandler, Command)
Declaration
protected void AddTextToolbarItem<T>(string text, Func<T, bool> getter, string memberName, T source = default, bool isNegated = false, EventHandler handler = null, Command command = null)
Parameters
| string text |
| Func<T, bool> getter |
| string memberName |
| T source |
| bool isNegated |
| EventHandler handler |
| Command command |
Type Parameters
| T |
AddToolbarItem(ToolbarItem)
CancelSource(CancellationTokenSource)
主动取消令牌信号。
Declaration
protected static bool CancelSource(CancellationTokenSource cts)
Parameters
|
CancellationTokenSource
cts
取消令牌源 |
Returns
|
bool
令牌不为 null 且被取消成功则返回 true |
CreateProperty<T, V>(string, T, BindingMode, Action<V, T>)
根据返回类型、名称、默认值、默认绑定模式快速创建属性。
Declaration
protected static BindableProperty CreateProperty<T, V>(string name, T defaultValue = default, BindingMode defaultBindingMode = BindingMode.OneWay, Action<V, T> propertyChanged = null) where V : BindableObject
Parameters
|
string
name
属性名称 |
|
T
defaultValue
属性初始值,默认为该类型的默认值 |
|
BindingMode
defaultBindingMode
属性绑定模式,默认为 OneWay |
|
Action<V, T>
propertyChanged
属性修改回调,传递参数为对象元素和修改后的属性值 |
Returns
|
BindableProperty
返回创建的属性 |
Type Parameters
|
T
属性返回类型 |
|
V
所属类型 |
Debounce(Action<CancellationToken>, int, bool)
根据自定义最低间隔去抖动执行方法。
Declaration
protected void Debounce(Action<CancellationToken> action, int delay = 400, bool keepContext = false)
Parameters
|
Action<CancellationToken>
action
调用的方法 |
|
int
delay
最小间隔,默认为 400ms |
|
bool
keepContext
是否以 UI 线程调用,默认 false |
GetTitleHeaderView()
获取页面标题视图。
Declaration
protected virtual IView GetTitleHeaderView()
Returns
|
IView
默认返回文本内容为 Title 的标签元素,超长则从中间截断 |
GetToolbarItem<T>(string, bool, Func<T, bool>, string, T, bool, EventHandler, Command)
Declaration
protected static ToolbarItem GetToolbarItem<T>(string text, bool isIcon, Func<T, bool> getter, string memberName, T source = default, bool isNegated = false, EventHandler handler = null, Command command = null)
Parameters
| string text |
| bool isIcon |
| Func<T, bool> getter |
| string memberName |
| T source |
| bool isNegated |
| EventHandler handler |
| Command command |
Returns
| ToolbarItem |
Type Parameters
| T |
InvokeDelayed(Action, TimeSpan, bool, bool, string)
以自定义间隔执行方法,并捕获错误,根据参数设置显示弹窗。
Declaration
protected bool InvokeDelayed(Action action, TimeSpan delayed = default, bool displayAlert = false, bool keepLoading = false, string source = null)
Parameters
|
Action
action
调用的方法 |
|
TimeSpan
delayed
延迟时间,默认为 DelayedTime |
|
bool
displayAlert
是否显示错误弹窗,默认为 false |
|
bool
keepLoading
是否保持 IsLoading,默认为 false |
|
string
source
调用源 |
Returns
|
bool
若执行成功返回 true |
OnAppearing()
When overridden in a derived class, allows application developers to customize behavior immediately prior to the page becoming visible.
Declaration
protected override void OnAppearing()
Overrides
OnBackAsync()
子类重写时可自定义返回指令的行为,默认先判断是否可在加载时关闭,堆栈有页面时返回上一页,否则返回主路由。
Declaration
protected virtual Task OnBackAsync()
Returns
| Task |
OnBackButtonPressed()
Determines the behavior when the back button of the page is pressed.
Declaration
protected override bool OnBackButtonPressed()
Returns
|
bool
true when the back navigation was handled by the override, otherwise false. |
Overrides
Remarks
Application developers can override this method to provide behavior when the back button is pressed. When overridden to handle or cancel the navigation yourself, this method should return true.
OnBackInternalAsync(bool)
Declaration
protected virtual Task OnBackInternalAsync(bool animated = true)
Parameters
| bool animated |
Returns
| Task |
OnDisappearing()
When overridden in a derived class, allows the application developer to customize behavior as the page disappears.
Declaration
protected override void OnDisappearing()
Overrides
Remarks
This method is called when the page disappears due to navigating away from the page within the app. It is not called when the app disappears due to an event external to the app (e.g. user navigates to the home screen or another app, a phone call is received, the device is locked, the device is turned off).
OnNavigatedFrom(NavigatedFromEventArgs)
OnNavigatedTo(NavigatedToEventArgs)
OnNetworkChanged(bool)
OnPageLoaded()
页面加载时调用的方法,若页面未销毁,多次 Push 该页面则调用多次。
Declaration
protected virtual void OnPageLoaded()
OnPageNavigated()
OnPageUnloaded()
页面卸载时调用的方法。
Declaration
protected virtual void OnPageUnloaded()
OnTitleTapped()
子类重写时可自定义标题点击时的行为,默认为滚动 MainCollectionView 的内容至首行。
Declaration
protected virtual void OnTitleTapped()
R(string, string)
获取语言资源。
Declaration
protected static string R(string lgid, string def = null)
Parameters
|
string
lgid
语言资源 ID |
|
string
def
资源默认字符串 |
Returns
|
string
返回资源在当前语言下的内容,未找到则返回 |
RemoveToolbarItem(ToolbarItem)
StartWatch()
Tap(Action)
执行自定义方法,确保方法执行完成之前只触发一次。
Declaration
protected void Tap(Action action)
Parameters
|
Action
action
调用的方法 |
Tap(Func<Task>)
执行自定义任务,确保任务执行完成之前只触发一次。
Declaration
protected void Tap(Func<Task> action)
Parameters
|
Func<Task>
action
调用的任务 |
Throttle(Action<CancellationToken>, int, bool)
根据自定义最低间隔节流执行方法。
Declaration
protected void Throttle(Action<CancellationToken> action, int delay = 400, bool keepContext = false)
Parameters
|
Action<CancellationToken>
action
调用的方法 |
|
int
delay
最小间隔,默认为 400ms |
|
bool
keepContext
是否以 UI 线程调用,默认 false |
TriggerLoadingItem<T>(object, Action<T>, bool, Action)
触发条目时可调用的糖函数,设置 IsLoading 为 true,执行回调完成后重置。
Declaration
protected void TriggerLoadingItem<T>(object o, Action<T> action, bool keepLoading = false, Action final = null) where T : ILoading
Parameters
|
object
o
命令参数对象 |
|
Action<T>
action
待执行的回调 |
|
bool
keepLoading
是否保持 IsLoading 为 true |
|
Action
final
最终执行的回调 |
Type Parameters
|
T
实现 ILoading 接口的类型 |