Compartir vía


Selector.IsSynchronizedWithCurrentItem Propiedad

Definición

Obtiene o establece un valor que indica si un Selector debe mantener la SelectedItem sincronizada con el elemento actual en la propiedad Items.

public:
 property Nullable<bool> IsSynchronizedWithCurrentItem { Nullable<bool> get(); void set(Nullable<bool> value); };
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter("System.Windows.NullableBoolConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
[System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
public bool? IsSynchronizedWithCurrentItem { get; set; }
[System.ComponentModel.Bindable(true)]
[System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
[System.ComponentModel.TypeConverter("System.Windows.NullableBoolConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public bool? IsSynchronizedWithCurrentItem { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.TypeConverter("System.Windows.NullableBoolConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)>]
member this.IsSynchronizedWithCurrentItem : Nullable<bool> with get, set
[<System.ComponentModel.Bindable(true)>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)>]
[<System.ComponentModel.TypeConverter("System.Windows.NullableBoolConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
member this.IsSynchronizedWithCurrentItem : Nullable<bool> with get, set
Public Property IsSynchronizedWithCurrentItem As Nullable(Of Boolean)

Valor de propiedad

true si el SelectedItem siempre está sincronizado con el elemento actual en el ItemCollection; false si el SelectedItem nunca se sincroniza con el elemento actual; null si el SelectedItem se sincroniza con el elemento actual solo si el Selector usa un CollectionView. El valor predeterminado es null.

Atributos

Ejemplos

En el ejemplo siguiente se enlazan dos controles de ListBox a la misma ItemsSource. Dado que IsSynchronizedWithCurrentItem se establece en true en cada ListBox, el elemento seleccionado siempre es el mismo para ambos controles.

<XmlDataProvider x:Key="Employees" XPath="/Employees/*">
  <x:XData>
    <Employees xmlns="">
      <Employee Name="Terry Adams" Type="FTE" EmployeeNumber="1" />
      <Employee Name="Claire O'Donnell" Type="FTE" EmployeeNumber="12345" />
      <Employee Name="Palle Peterson" Type="FTE" EmployeeNumber="5678" />
      <Employee Name="Amy E. Alberts" Type="CSG" EmployeeNumber="99222" />
      <Employee Name="Stefan Hesse" Type="Vendor" EmployeeNumber="-" />
    </Employees>
  </x:XData>
</XmlDataProvider>

<DataTemplate x:Key="EmployeeItemTemplate">
  <TextBlock Text="{Binding XPath=@Name}" />
</DataTemplate>
<ListBox Name="employeeListBox1"
         ItemsSource="{Binding Source={StaticResource Employees}}"
         ItemTemplate="{StaticResource EmployeeItemTemplate}"
         IsSynchronizedWithCurrentItem="True"/>

<ListBox Name="employeeListBox2"
         ItemsSource="{Binding Source={StaticResource Employees}}"
         ItemTemplate="{StaticResource EmployeeItemTemplate}"
         IsSynchronizedWithCurrentItem="True"/>

Comentarios

Puede establecer la propiedad IsSynchronizedWithCurrentItem en true para asegurarse de que el elemento seleccionado siempre corresponde a la propiedad CurrentItem de la ItemCollection. Por ejemplo, supongamos que hay dos controles ListBox con su propiedad ItemsSource establecida en el mismo origen. Establezca IsSynchronizedWithCurrentItem en true en ambos cuadros de lista para asegurarse de que el elemento seleccionado de cada ListBox sea el mismo.

Uso de atributos XAML

< objetoIsSynchronizedWithCurrentItem="Boolean"/>

-o-

< objetoIsSynchronizedWithCurrentItem="{}"/>

Información de la propiedad dependency

Campo identificador IsSynchronizedWithCurrentItemProperty
Propiedades de metadatos establecidas en true Ninguno

Se aplica a