我有一个列表框.列表框与数据集绑定(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/