ComboBox に項目を動的に追加しようとしました。
ただし、「ItemsSource が使用されている間、操作は無効です。代わりに、ItemsControl.ItemsSource を使用して要素にアクセスして変更してください」という例外がスローされます。
namespace Trainning
{
public partial class ComboBox : Window
{
int intex_count;
public ComboBox()
{
this.InitializeComponent();
add_items();
}
public List<object> add_items()
{
List<object> items = new List<object>();
items.Add("chandru");
items.Add(83);
com_add_remove.ItemsSource = items;
com_add_remove.SelectedIndex = 0;
return items;
}
private void btn_add_Click(object sender, RoutedEventArgs e)
{
com_add_remove.Items.Add(txt_item.Text);
intex_count = com_add_remove.Items.Count;
com_add_remove.SelectedIndex = intex_count - 1;
}