Selector.IsSynchronizedWithCurrentItem 屬性

定義

取得或設定值,這個值表示 Selector 是否應該讓 SelectedItemItems 屬性中的目前專案保持同步。

C#
[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; }
C#
[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; }

屬性值

true 如果 SelectedItem 一律與 ItemCollection中的目前專案同步處理;如果 SelectedItem 永遠不會與目前專案同步處理,false;只有在 Selector 使用 CollectionView時,nullSelectedItem 才會與目前專案同步處理。 預設值為 null

屬性

範例

下列範例會將兩個 ListBox 控件系結至相同的 ItemsSource。 由於 IsSynchronizedWithCurrentItem 設定為在每個 ListBoxtrue,因此兩個控件的選取專案一律相同

XAML
<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>
XAML
<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,以確保選取的專案一律對應至 ItemCollection中的 CurrentItem 屬性。 例如,假設有兩個 ListBox 控件,其 ItemsSource 屬性設定為相同的來源。 將 IsSynchronizedWithCurrentItem 設定為在這兩個清單框中 true,以確保每個 ListBox 中選取的專案都相同。

XAML 屬性使用方式

< 物件IsSynchronizedWithCurrentItem=“Boolean”/>

-或-

< 物件IsSynchronizedWithCurrentItem=“{}”/>

相依性屬性資訊

標識元欄位 IsSynchronizedWithCurrentItemProperty
設定為 true 的元數據屬性 沒有

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9