Proprietà BindingBase.FallbackValue (System.Windows.Data)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Proprietà BindingBase.FallbackValue
Il presente articolo è stato tradotto manualmente. Per visualizzare questa pagina e contemporaneamente visualizzarne il contenuto in lingua inglese, passare alla visualizzazione semplificata.

Ottiene o imposta il valore da utilizzare quando l'associazione non è in grado di restituire un valore.

Spazio dei nomi:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS per XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Sintassi

Visual Basic
Public Property FallbackValue As Object
	Get
	Set
C#
public Object FallbackValue { get; set; }
Visual C++
public:
property Object^ FallbackValue {
	Object^ get ();
	void set (Object^ value);
}
F#
member FallbackValue : Object with get, set

XAML
<object FallbackValue="fallbackValue" />

Valor XAML

fallbackValue

Un valore dell'attributo o dell'elemento oggetto dello stesso tipo della proprietà di destinazione. Per informazioni sull’utilizzo di XAML, vedere la documentazione sul tipo specificato. Il tipo può o non può supportare la sintassi dell'attributo per i valori, oppure può o non può supportare la sintassi dell'elemento oggetto (che richiede un costruttore predefinito su quel tipo). Il tipo della proprietà di destinazione influenzerà quindi la sintassi utilizzata per il valore della proprietà FallbackValue.

Valore proprietà

Tipo: System.Object
Il valore predefinito è DependencyProperty.UnsetValue.
Note

Un'associazione restituisce correttamente un valore se:

  1. Il percorso dell'origine di associazione viene risolto correttamente.

  2. Il convertitore di valore, se presente, è in grado di convertire il valore risultante.

  3. Il valore risultante è valido per la proprietà (destinazione) della destinazione di associazione.

Se 1 e 2 restituiscono DependencyProperty.UnsetValue, la proprietà di destinazione è impostata sul valore di FallbackValue, se disponibile. Se non esiste alcun oggetto FallbackValue, viene utilizzato il valore della proprietà di destinazione.

Il valore DependencyProperty.UnsetValue non è considerato un valore restituito corretto.

Esempi

PriorityBinding in Windows Presentation Foundation (WPF) works by specifying a list of bindings. The list of bindings is ordered from highest priority to lowest priority. If the highest priority binding returns a value successfully when it is processed then there is never a need to process the other bindings in the list. It could be the case that the highest priority binding takes a long time to be evaluated, the next highest priority that returns a value successfully will be used until a binding of a higher priority returns a value successfully.

To demonstrate how PriorityBinding works, the AsyncDataSource object has been created with the following three properties: FastDP, SlowerDP, and SlowestDP.

The get accessor of FastDP returns the value of the _fastDP data member.

The get accessor of SlowerDP waits for 3 seconds before returning the value of the _slowerDP data member.

The get accessor of SlowestDP waits for 5 seconds before returning the value of the _slowestDP data member.

Nota Nota

This example is for demonstration purposes only. The Microsoft .NET guidelines recommend against defining properties that are orders of magnitude slower than a field set would be. For more information, see Scelta tra proprietà e metodi.

Visual Basic

Public Class AsyncDataSource
    ' Properties
    Public Property FastDP As String
        Get
            Return Me._fastDP
        End Get
        Set(ByVal value As String)
            Me._fastDP = value
        End Set
    End Property

    Public Property SlowerDP As String
        Get
            Thread.Sleep(3000)
            Return Me._slowerDP
        End Get
        Set(ByVal value As String)
            Me._slowerDP = value
        End Set
    End Property

    Public Property SlowestDP As String
        Get
            Thread.Sleep(5000)
            Return Me._slowestDP
        End Get
        Set(ByVal value As String)
            Me._slowestDP = value
        End Set
    End Property


    ' Fields
    Private _fastDP As String
    Private _slowerDP As String
    Private _slowestDP As String
End Class


C#

public class AsyncDataSource
{
	private string _fastDP;
	private string _slowerDP;
	private string _slowestDP;

	public AsyncDataSource()
	{
	}

	public string FastDP
	{
    get { return _fastDP; }
    set { _fastDP = value; }
	}

	public string SlowerDP
	{
    get
    {
      // This simulates a lengthy time before the
      // data being bound to is actualy available.
      Thread.Sleep(3000);
      return _slowerDP;
    }
    set { _slowerDP = value; }
	}

	public string SlowestDP
	{
    get
    {
      // This simulates a lengthy time before the
      // data being bound to is actualy available.
      Thread.Sleep(5000);
      return _slowestDP;
    }
    set { _slowestDP = value; }
	}
}


The Text property binds to the above AsyncDS using PriorityBinding:

XAML

<Window.Resources>
  <c:AsyncDataSource SlowestDP="Slowest Value" SlowerDP="Slower Value"
                     FastDP="Fast Value" x:Key="AsyncDS" />
</Window.Resources>
	
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"
  DataContext="{Binding Source={StaticResource AsyncDS}}">
  <TextBlock FontSize="18" FontWeight="Bold" Margin="10"
    HorizontalAlignment="Center">Priority Binding</TextBlock>
  <TextBlock Background="Honeydew" Width="100" HorizontalAlignment="Center">
    <TextBlock.Text>
      <PriorityBinding FallbackValue="defaultvalue">
        <Binding Path="SlowestDP" IsAsync="True"/>
        <Binding Path="SlowerDP" IsAsync="True"/>
        <Binding Path="FastDP" />
      </PriorityBinding>
    </TextBlock.Text>
  </TextBlock>	
</StackPanel>


When the binding engine processes the Binding objects, it starts with the first Binding, which is bound to the SlowestDP property. When this Binding is processed, it does not return a value successfully because it is sleeping for 5 seconds, so the next Binding element is processed. The next Binding does not return a value successfully because it is sleeping for 3 seconds. The binding engine then moves onto the next Binding element, which is bound to the FastDP property. This Binding returns the value "Fast Value". The TextBlock now displays the value "Fast Value".

After 3 seconds elapses, the SlowerDP property returns the value "Slower Value". The TextBlock then displays the value "Slower Value".

After 5 seconds elapses, the SlowestDP property returns the value "Slowest Value". That binding has the highest priority because it is listed first. The TextBlock now displays the value "Slowest Value".

See PriorityBinding for information about what is considered a successful return value from a binding.

Informazioni sulla versione

.NET Framework

Supportato in: 4, 3.5, 3.0

.NET Framework Client Profile

Supportato in: 4, 3.5 SP1
Piattaforme

Windows 7, Windows Vista SP1 o versione successiva, Windows XP SP3, Windows Server 2008 (componenti di base del server non supportati), Windows Server 2008 R2 (componenti di base del server supportati con SP1 o versione successiva), Windows Server 2003 SP2

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Vedere anche

Riferimenti