Share via


BindableObject.BindingContextProperty 欄位

定義

BindingContext可系結屬性。

public: static initonly Microsoft::Maui::Controls::BindableProperty ^ BindingContextProperty;
public static readonly Microsoft.Maui.Controls.BindableProperty BindingContextProperty;
 staticval mutable BindingContextProperty : Microsoft.Maui.Controls.BindableProperty
Public Shared ReadOnly BindingContextProperty As BindableProperty 

欄位值

備註

一般而言,如果在 BindingContext 進行所有呼叫 SetBinding(BindableProperty, BindingBase) 之後設定,運行時間效能會更好。

下列範例示範如何將系結設定為 BindingContext:

class PersonView : ContentView 
{
  public PersonView ()
  {
    var label = new Label ();
    label.SetBinding (Label.TextProperty, "Name");
    Content = label;
  }
}

var stack = new StackLayout {
  Orientation = StackOrientation.Vertical,  
};

var jane = new PersonView ();
jane.SetBinding (BindableObject.BindingContext, "Jane");
stack.Children.Add (jane);

var john = new PersonView ();
john.SetBinding (BindableObject.BindingContext, "John");
stack.Children.Add (john);

stack.BindingContext = new {Jane = new {Name = "Jane Doe"}, John = new {Name = "John Doe"}};

適用於