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. 因為 IsSynchronizedWithCurrentItemtrue 在每個上將設為 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 Attribute UsageXAML Attribute Usage

<物件 IsSynchronizedWithCurrentItem= " Boolean "/><object IsSynchronizedWithCurrentItem="Boolean"/>

-或--or-

<物件 IsSynchronizedWithCurrentItem= " {} "/><object IsSynchronizedWithCurrentItem="{}"/>

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field IsSynchronizedWithCurrentItemProperty
中繼資料屬性設定為trueMetadata properties set to true None

適用於