如何冻结ListBox
直到Thread
结束,以防止SelectedIndex
突出损失?
这是我的实际代码(但是当我禁用并启用ListBox时,选择突出显示会丢失):
ListBox_DeviceList.IsEnabled = false;
if (ListBox_DeviceList.SelectedItem != null)
{
bool error = await GetAvailableJobs();
//enables when Task ends ...
ListBox_DeviceList.IsEnabled = true;
if (error)
{
//do something
}
else
{
//do something
}
}
我认为您需要将Enable属性(使用.IsEnabled)设置为false,最后设置为true。
ListBox_DeviceList.Enabled = false;
if (ListBox_DeviceList.SelectedItem != null)
{
bool error = await GetAvailableJobs();
//enables when Task ends ...
ListBox_DeviceList.Enabled = true;
if (error)
{
//do something
}
else
{
//do something
}
}
其他方式,是调用SuspendLayout()和ResumeLayout()方法。
ListBox_DeviceList.SuspendLayout();
if (ListBox_DeviceList.SelectedItem != null)
{
bool error = await GetAvailableJobs();
//enables when Task ends ...
ListBox_DeviceList.ResumeLayout();
if (error)
{
//do something
}
else
{
//do something
}
}