Application 类

定义

表示跨平台移动应用程序的类。

public class Application : Xamarin.Forms.Element, Xamarin.Forms.IApplicationController, Xamarin.Forms.IElementConfiguration<Xamarin.Forms.Application>
type Application = class
    inherit Element
    interface IApplicationController
    interface IElementConfiguration<Application>
继承
实现

注解

Application类是 Xamarin.Forms 应用程序的核心。 它设置应用程序的根页,在字典中 Properties 对应用程序的调用中保留基元类型数据,并提供事件来响应模式视图的推送和弹出。 Visual Studio 在新的 Xamarin.Forms 解决方案中的相应项目中为开发人员创建此类。

当开发人员创建新的 Xamarin.Forms 解决方案时,Visual Studio for Mac和 Visual Studio 都为应用程序创建 XAML 和代码隐藏文件。 以下示例演示一个典型的 Application 类,其资源字典中具有一个条目。

<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App1.App">
<Application.Resources>
<Color x:Key="ButtonBackgroundColor">Red</Color>
</Application.Resources>
</Application>
public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new MainPage();
    }

    protected override void OnStart()
    {
        // Handle when your app starts
    }

    protected override void OnSleep()
    {
        // Handle when your app sleeps
    }

    protected override void OnResume()
    {
        // Handle when your app resumes
    }
}

构造函数

Application()

初始化一个新 Application 实例。

属性

AppLinks

获取开发者用于注册或取消注册应用程序链接的对象。

AutomationId

获取或设置允许自动化框架查找此元素并与其交互的值。

(继承自 Element)
BindingContext

获取或设置对象,该对象包含将被属于此 BindableObject 的绑定属性设定为目标的属性。

(继承自 BindableObject)
ClassId

获取或设置用于标识语义相似元素集合的值。

(继承自 Element)
Current

获取当前应用程序。

Dispatcher

表示跨平台移动应用程序的类。

EffectControlProvider

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
Effects

应用于此项的效果列表。

(继承自 Element)
Id

获取可用于通过运行应用程序唯一地标识元素的值。

(继承自 Element)
LogicalChildren

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
LogWarningsToApplicationOutput
已过时。

获取或设置是否将运行时警告发送给应用程序的输出。

MainPage

获取或设置应用程序的根页面。

NavigationProxy

供 Xamarin.Forms 平台内部使用。

PanGestureId

供 Xamarin.Forms 平台内部使用。

Parent

获取或设置元素的父元素。

(继承自 Element)
ParentView
已过时。

获取作为 VisualElement 的此元素的最近的上级元素。

(继承自 Element)
Platform
已过时。

表示跨平台移动应用程序的类。

(继承自 Element)
Properties

获取此 Application 对象的永久属性字典。

RealParent

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
RequestedTheme

表示跨平台移动应用程序的类。

Resources

获取或设置此 Application 对象的资源字典。

StyleId

获取或设置用于唯一地标识元素的用户定义的值。

(继承自 Element)
UserAppTheme

表示跨平台移动应用程序的类。

方法

ApplyBindings()

将绑定应用到 BindingContext

(继承自 BindableObject)
CleanUp()

表示跨平台移动应用程序的类。

ClearCurrent()

供 Xamarin.Forms 平台内部使用。

ClearValue(BindableProperty)

清除由 SetValueproperty 设置的任何值。

(继承自 BindableObject)
ClearValue(BindablePropertyKey)

清除由 SetValuepropertyKey 标识的属性设置的任何值。

(继承自 BindableObject)
CoerceValue(BindableProperty)

表示跨平台移动应用程序的类。

(继承自 BindableObject)
CoerceValue(BindablePropertyKey)

表示跨平台移动应用程序的类。

(继承自 BindableObject)
Descendants()

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
EffectIsAttached(String)

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
FindByName(String)

返回具有指定名称的元素。

(继承自 Element)
GetValue(BindableProperty)

返回 BindableProperty 中包含的值。

(继承自 BindableObject)
GetValues(BindableProperty, BindableProperty)
已过时。

供 Xamarin.Forms 平台内部使用。

(继承自 BindableObject)
GetValues(BindableProperty, BindableProperty, BindableProperty)
已过时。

供 Xamarin.Forms 平台内部使用。

(继承自 BindableObject)
IsApplicationOrNull(Element)

供 Xamarin.Forms 平台内部使用。

IsSet(BindableProperty)

如果目标属性存在并且已设置,则返回 true

(继承自 BindableObject)
On<T>()

返回此 Application 的特定于平台的实例,可对其调用特定于平台的方法。

OnAppLinkRequestReceived(Uri)

用户发起应用链接请求时,应用开发者会替代此方法以进行响应。

OnBindingContextChanged()

每当元素的绑定上下文发生更改时就会调用。 实现此方法可为此事件添加类处理。

(继承自 Element)
OnChildAdded(Element)

每当需要发出 ChildAdded 事件时就会调用。 实现此方法可为此事件添加类处理。

(继承自 Element)
OnChildRemoved(Element)
已过时。

每当需要发出 ChildRemoved 事件时就会调用。 实现此方法可为此事件添加类处理。

(继承自 Element)
OnChildRemoved(Element, Int32)

表示跨平台移动应用程序的类。

(继承自 Element)
OnParentSet()

引发 InvalidOperationException

OnPropertyChanged(String)

更改绑定属性时调用的方法。

(继承自 Element)
OnPropertyChanging(String)

从子类调用此方法以通知属性将要发生更改。

(继承自 BindableObject)
OnResume()

应用程序从睡眠状态恢复时,应用开发者会替代此方法以执行操作。

OnSleep()

应用程序进入睡眠状态时,应用开发者会替代此方法以执行操作。

OnStart()

应用程序启动时,应用开发者会替代此方法以执行操作。

Quit()

退出应用程序。

RemoveBinding(BindableProperty)

删除先前设置的绑定。

(继承自 BindableObject)
RemoveDynamicResource(BindableProperty)

移除先前设置的动态资源

(继承自 Element)
SavePropertiesAsync()

以异步方式永久保留应用程序对象的 Properties 字典。

SendOnAppLinkRequestReceived(Uri)

供 Xamarin.Forms 平台内部使用。

SendResume()

供 Xamarin.Forms 平台内部使用。

SendSleep()

供 Xamarin.Forms 平台内部使用。

SendSleepAsync()

供 Xamarin.Forms 平台内部使用。

SendStart()

供 Xamarin.Forms 平台内部使用。

SetAppIndexingProvider(IAppIndexingProvider)

供 Xamarin.Forms 平台内部使用。

SetBinding(BindableProperty, BindingBase)

向属性分配绑定。

(继承自 BindableObject)
SetCurrentApplication(Application)

供 Xamarin.Forms 平台内部使用。

SetDynamicResource(BindableProperty, String)

将此元素的 BindableProperty 属性设置为通过 DynamicResource 使用提供的键来更新。

(继承自 Element)
SetValue(BindableProperty, Object)

设置指定属性的值。

(继承自 BindableObject)
SetValue(BindablePropertyKey, Object)

设置 propertyKey 的值。

(继承自 BindableObject)
SetValueCore(BindableProperty, Object, SetValueFlags)

供 Xamarin.Forms 平台内部使用。

(继承自 BindableObject)
SetValueFromRenderer(BindableProperty, Object)

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
SetValueFromRenderer(BindablePropertyKey, Object)

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
TriggerThemeChanged(AppThemeChangedEventArgs)

表示跨平台移动应用程序的类。

UnapplyBindings()

不应用所有以前设置的绑定。

(继承自 BindableObject)

事件

BindingContextChanged

只要 BindingContext 属性更改就会引发。

(继承自 BindableObject)
ChildAdded

每当将子元素添加到元素时就会发生。

(继承自 Element)
ChildRemoved

每当从元素中删除子元素时就会发生。

(继承自 Element)
DescendantAdded

每当将子元素添加到元素子树时就会发生。

(继承自 Element)
DescendantRemoved

每当从元素子树中删除子元素时就会发生。

(继承自 Element)
ModalPopped

以模式方式弹出视图后将引发的事件。

ModalPopping

以模式方式弹出视图时引发的事件。

ModalPushed

以模式方式推送视图后将引发的事件。

ModalPushing

以模式方式推送视图时引发的事件。

PageAppearing

页面即将在屏幕上显示时引发的事件。

PageDisappearing

页面即将从屏幕上消失时引发的事件。

PlatformSet
已过时。

表示跨平台移动应用程序的类。

(继承自 Element)
PropertyChanged

在属性已更改时引发。

(继承自 BindableObject)
PropertyChanging

在属性将要更改时引发。

(继承自 BindableObject)
RequestedThemeChanged

表示跨平台移动应用程序的类。

显式接口实现

IDynamicResourceHandler.SetDynamicResource(BindableProperty, String)

供 Xamarin.Forms 平台内部使用。

(继承自 BindableObject)
IElementController.SetValueFromRenderer(BindableProperty, Object)

供 Xamarin.Forms 平台内部使用。

(继承自 Element)
INameScope.RegisterName(String, Object)

仅限内部使用。

(继承自 Element)

扩展方法

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)

表示跨平台移动应用程序的类。

SetAppThemeColor(BindableObject, BindableProperty, Color, Color)

表示跨平台移动应用程序的类。

SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)

创建绑定并将其应用到属性。

SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String)
已过时。

通过表达式创建并应用绑定。

SetOnAppTheme<T>(BindableObject, BindableProperty, T, T)

表示跨平台移动应用程序的类。

FindByName<T>(Element, String)

返回包含 element 的作用域中名称为 name 的类型 T 的实例。

适用于