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 方案的適當專案中,為開發人員建立此類別。

Visual Studio for Mac和 Visual Studio 會在開發人員建立新的 Xamarin.Forms 解決方案時,為應用程式建立 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)

清除 SetValue 針對 property 所設定的任何值。

(繼承來源 BindableObject)
ClearValue(BindablePropertyKey)

清除 SetValue 針對 propertyKey 所識別屬性設定的任何值。

(繼承來源 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)

透過具有所提供索引鍵的 DynamicResource,設定更新此項目的 BindableProperty 屬性。

(繼承來源 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 類型執行個體。

適用於