BindableObject.SetValue Metodo

Definizione

Overload

SetValue(BindableProperty, Object)

Imposta il valore della proprietà specificata.

SetValue(BindablePropertyKey, Object)

Imposta il valore di propertyKey.

SetValue(BindableProperty, Object)

Imposta il valore della proprietà specificata.

public void SetValue (Xamarin.Forms.BindableProperty property, object value);
member this.SetValue : Xamarin.Forms.BindableProperty * obj -> unit

Parametri

property
BindableProperty

BindableProperty alla quale assegnare un valore.

value
Object

Il valore da impostare.

Commenti

GetValue(BindableProperty)e SetValue vengono usati per accedere ai valori delle proprietà implementate da un oggetto BindableProperty . Ovvero, gli sviluppatori di applicazioni forniscono in genere un'interfaccia per una proprietà associata definendo public la proprietà la cui get funzione di accesso esegue il cast del risultato al GetValue(BindableProperty) tipo appropriato e la restituisce e la cui set funzione di accesso usa SetValue per impostare il valore sulla proprietà corretta. Gli sviluppatori di applicazioni non devono eseguire altri passaggi nella proprietà pubblica che definisce l'interfaccia della proprietà associata.

Nell'esempio seguente viene illustrato come creare un'interfaccia di proprietà associabile per un'implementazione che verrà fornita nella proprietà di destinazione quando l'associazione viene eseguita in fase di esecuzione.

class MyBindable : BindableObject
{
    public static readonly BindableProperty MyProperty = 
      BindableProperty.Create<MyBindable, string> (w => w.My, default(string));

    public string My {
      get { return (string)GetValue (MyProperty); }
      set { SetValue (MyProperty, value); } 
    }
}

Si applica a

SetValue(BindablePropertyKey, Object)

Imposta il valore di propertyKey.

public void SetValue (Xamarin.Forms.BindablePropertyKey propertyKey, object value);
member this.SetValue : Xamarin.Forms.BindablePropertyKey * obj -> unit

Parametri

propertyKey
BindablePropertyKey

BindablePropertyKey alla quale assegnare un valore.

value
Object

Il valore da impostare.

Commenti

Questo metodo e BindablePropertyKey sono utili per implementare BindableProperties con accesso in scrittura limitato. L'accesso in scrittura è limitato all'ambito di BindablePropertyKey.

Nell'esempio seguente viene illustrato come dichiarare bindableProperty con accesso in scrittura "interno".

class MyBindable : BindableObject
{
  internal static readonly BindablePropertyKey MyPropertyKey = 
    BindableProperty.CreateReadOnly<MyBindable, string> (w => w.My, default(string));
  public static readonly BindableProperty MyProperty = MyPropertyKey.BindableProperty;

  public string My {
    get { return (string)GetValue (MyProperty); }
    internal set { SetValue (MyPropertyKey, value); } 
  }
}

Si applica a