Я пытался вызвать combobox, чтобы заполнить его ItemSource
и использовать его источник предметов во время Invoking, но я не могу использовать его до завершения вызова, я хочу использовать его во время вызова.Мое контрольное имя в Gui cb_attach
.Мой контрольный элемент управления tempattachcombobox
.
private void cb_attach_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
tempattachcombobox = sender as ComboBox;
Thread UpdateComboboxThread = new Thread(UpdateCombobox);
UpdateComboboxThread.Start();
}
private void UpdateCombobox()
{
while (GlobalV.Working == true)
{
int tempselectedindex = -1;
tempattachcombobox.Dispatcher.Invoke(
DispatcherPriority.Normal,
new Action(delegate() { tempselectedindex = tempattachcombobox.SelectedIndex; }));
List<int> numberList = Enumerable.Range(0, GlobalV.Attatched_Elements.Count).ToList();
tempattachcombobox.Dispatcher.Invoke(
DispatcherPriority.Normal,
new Action(delegate()
{
tempattachcombobox.ItemsSource = numberList;
tempattachcombobox.SelectedIndex = tempselectedindex;
}));
}
MessageBox.Show("Process Completed!", "Process Status", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void cb_attach_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (drawattach == false)
{
try
{
real_area.DrawingArea.Children.Clear();
real_area.DrawGrid(25);
real_area.DrawElement(GlobalV.Current_Elements[0]);
real_area.DrawElement_Using_Points(GlobalV.Current_Elements[1], cb_attach.SelectedIndex);
}
catch { }
}
else
{
try
{
real_area.DrawingArea.Children.Clear();
real_area.DrawGrid(25);
real_area.DrawElement(GlobalV.Attatched_Elements[cb_attach.SelectedIndex]);
real_area.DrawHash(GlobalV.Attatched_Elements[cb_attach.SelectedIndex]);
}
catch { }
}
}
realarea, работающий в главном потоке графического интерфейса пользователя