Selector.IsSynchronizedWithCurrentItem 属性

定义

获取或设置指示 Selector 是否应当使 SelectedItemItems 属性中的当前项保持同步的值。Gets or sets a value that indicates whether a Selector should keep the SelectedItem synchronized with the current item in the Items property.

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=4.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=3.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=4.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=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
member this.IsSynchronizedWithCurrentItem : Nullable<bool> with get, set
Public Property IsSynchronizedWithCurrentItem As Nullable(Of Boolean)

属性值

Nullable<Boolean>

如果 SelectedItem 始终与 ItemCollection 中的当前项保持同步,则为 true;如果 SelectedItem 从不与当前项保持同步,则为 false;如果 SelectedItem 只有在 Selector 使用 CollectionView 时才与当前项保持同步,则为 nulltrue if the SelectedItem is always synchronized with the current item in the ItemCollection; false if the SelectedItem is never synchronized with the current item; null if the SelectedItem is synchronized with the current item only if the Selector uses a CollectionView. 默认值为 nullThe default value is null.

属性

示例

下面的示例将两个 ListBox 控件绑定到相同的 ItemsSourceThe following example binds two ListBox controls to the same ItemsSource. 由于 IsSynchronizedWithCurrentItem 设置为 true ,因此每个 ListBox 控件的选定项始终相同Because IsSynchronizedWithCurrentItem is set to true on each ListBox, the selected item is always the same for both controls

<XmlDataProvider x:Key="Employees" XPath="/Employees/*">
  <x:XData>
    <Employees xmlns="">
      <Employee Name="Terry Adams" Type="FTE" EmployeeNumber="1" />
      <Employee Name="Claire O&apos;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"/>

注解

您可以将 IsSynchronizedWithCurrentItem 属性设置为, true 以确保选定的项始终对应于 CurrentItem 中的属性 ItemCollectionYou can set the IsSynchronizedWithCurrentItem property to true to ensure that the item selected always corresponds to the CurrentItem property in the ItemCollection. 例如,假设有两个 ListBox 控件的 ItemsSource 属性设置为同一源。For example, suppose that there are two ListBox controls with their ItemsSource property set to the same source. IsSynchronizedWithCurrentItem true 对于这两个列表框,均设置为,以确保每个列表框中的选定项 ListBox 都相同。Set IsSynchronizedWithCurrentItem to true on both list boxes to ensure that the selected item in each ListBox is the same.

XAML 属性用法XAML Attribute Usage

<对象 IsSynchronizedWithCurrentItem= " Boolean "/><object IsSynchronizedWithCurrentItem="Boolean"/>

-或--or-

<对象 IsSynchronizedWithCurrentItem= " {} "/><object IsSynchronizedWithCurrentItem="{}"/>

依赖项属性信息Dependency Property Information

标识符字段Identifier field IsSynchronizedWithCurrentItemProperty
元数据属性设置为trueMetadata properties set to true NoneNone

适用于