【问题标题】:How to prevent ListBox from autoselecting first item when using CollectionViewSource [duplicate]使用 CollectionViewSource 时如何防止 ListBox 自动选择第一项
【发布时间】:2014-11-28 20:02:27
【问题描述】:

我有一个绑定到 CollectionViewSource 的 ListBox,文本框帮助我过滤掉集合。但是,ListBox 会自动选择第一项。如何防止自动选择发生?

代码:

<CollectionViewSource x:Key="caseCollection" Source="{Binding Cases}"></CollectionViewSource>
<StackPanel Orientation="Vertical" Background="White" Height="50">
    <sdk:Label Name="lblWat">Enter a case</sdk:Label>
    <TextBox Width="150" Height="23" x:Name="caseSearch" TextChanged="caseSearch_TextChanged" />                    
</StackPanel>
<ListBox ItemsSource="{Binding Source={StaticResource caseCollection}}" BorderThickness="0"  BorderBrush="Transparent"
                 ItemContainerStyle="{StaticResource AdminListBoxItemStyle}" 
                 SelectedItem="{Binding SelectedCase, Mode=TwoWay}" x:Name="lstCases"
                     SelectionMode="Single">

【问题讨论】:

    标签: c# wpf silverlight listbox


    【解决方案1】:

    您可以通过在 ListBox 上设置 IsSynchronizedWithCurrentItem="False" 来解决此问题

    【讨论】:

    • 这不是默认false吗?
    • @RohitVats 默认值为null
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2022-01-09
    相关资源
    最近更新 更多