IsSynchronizedWithCurrentItem attribute and current item updates

前端 未结 1 754
心在旅途
心在旅途 2021-01-02 03:57

I have a view model to manage a dialog type of view that allows filtering of a listing (if necessary) and selection of an item. The code works fine whether I set IsSynchroni

相关标签:
1条回答
  • 2021-01-02 04:31

    IsSynchronizedWithCurrentItem syncs the CurrentItem of the default CollectionView of the bound collection with the SelectedItem of your control.

    Since you never use the CurrentItem of the CollectionView and you do not appear to bind to the same collection twice setting the property in question has no visible effect at all.


    Demo of how the property syncs (for XAML viewers like XAMLPad):

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Page.Resources>
            <x:Array x:Key="Items" Type="{x:Type sys:String}">
                <sys:String>Apple</sys:String>
                <sys:String>Orange</sys:String>
                <sys:String>Pear</sys:String>
                <sys:String>Lime</sys:String>
            </x:Array>
        </Page.Resources>
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <StackPanel Background="Transparent">
                <ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{StaticResource Items}" />
                <ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{StaticResource Items}" />
                <!-- This TextBlock binds to the CurrentItem of the Items via the "/" -->
                <TextBlock Text="{Binding Source={StaticResource Items}, Path=/}"/>
            </StackPanel>
        </ScrollViewer>
    </Page>
    
    0 讨论(0)
提交回复
热议问题