wpf - 在wpf中滚动列表框时,列表框选择随机取消选择某些项目

标签 wpf listbox

我有一个列表框.列表框与数据集绑定(bind)。列表框绑定(bind)给出了正确的结果我在列表框中使用了复选框进行选择并且工作正常,但问题是当我检查某些项目列表框并滚动时向下滚动列表框并选中另一个项目,然后返回到滚动上方,然后随机自动取消选中某个项目。我不希望该项目自动取消选中。请帮我。我使用下面的代码。

<DataTemplate x:Key="listBoxcontrycode">
    <StackPanel Margin="4">
        <DockPanel>
            <CheckBox Name="chkcntrycode" Content="{Binding userisd}"
                      Checked="chkcntrycode_Checked" Unchecked="Unchkcntrycode_Checked" />
        </DockPanel>
    </StackPanel>

<ListBox Height="89" HorizontalAlignment="Left" ItemTemplate="{StaticResource listBoxcontrycode}" ItemsSource="{Binding Tables[0]}" Margin="160,0,0,6" 
         Name="listcntrycode" VerticalAlignment="Bottom" Width="86" Grid.Column="3" Grid.ColumnSpan="2" Grid.RowSpan="2"                                       
         OverridesDefaultStyle="False" SelectionMode="Extended" IsEnabled="True" Grid.Row="3" />  

.

private void ListBoxBindingcntrycode()
{
    DBConnection ob = new DBConnection();
    RMS_Dataobject.getConnectionString = System.Configuration.ConfigurationSettings.AppSettings["EDM_RDMServer"];
    string commandString = "use [" + cmbEDM.SelectedItem.ToString() + "] select userisd from ADS_Audit_Log";
    DataTable dt = new DataTable();
    dt = ob.ReturnDatatable(commandString);
    DataSet ds = new DataSet();
    ds.Tables.Add(dt);
    listcntrycode.DataContext = ds;
}

最佳答案

尝试将 IsChecked 绑定(bind)到 bool 属性。目前 IsChecked 未保存在任何地方,因此当回收该项目时,不会保存该信息。

关于wpf - 在wpf中滚动列表框时,列表框选择随机取消选择某些项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11333275/

相关文章:

WPF Treeview - 与 ViewModel 同步?

c# - 纯粹在 xaml 中连接文字和静态资源字符串

wpf - 如何在 ViewModel 之间正确共享 Entity Framework ContextObject?

wpf - 有没有人有在 MVVM 模式下工作的 WPF Datagrid 的代码示例?

wpf - 如何在WPF中获取Windows用户名

delphi - TListBox弹性滚动效果

delphi - TListBox - 所选项目滚动速度

选择多个值时列表框的 JavaScript 验证

C#/WPF : Dependency Property is not updating the bound Property?

python - 子类化 tk.Listbox 时出错(属性错误对象没有属性 'tk' )