Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF组合框更新但不显示组合框项源更改时的显示_C#_Wpf_Xaml - Fatal编程技术网

C# WPF组合框更新但不显示组合框项源更改时的显示

C# WPF组合框更新但不显示组合框项源更改时的显示,c#,wpf,xaml,C#,Wpf,Xaml,我是WPF的新手,尝试在keyup事件上设置一个自动提示组合框 Xaml代码:这是我的Xaml: C代码:代码隐藏 public partial class page_addsale : Page { List<string> nameList { get; set; } DataTable data = new DataTable(); List<string> autoList = new List&

我是WPF的新手,尝试在keyup事件上设置一个自动提示组合框

Xaml代码:这是我的Xaml:

C代码:代码隐藏


    public partial class page_addsale : Page
    {

        List<string> nameList { get; set; }
        DataTable data = new DataTable();
        List<string> autoList = new List<string>();

        public page_addsale()
        {
            InitializeComponent();

            nameList = new List<string>();

            con.Open();
            OleDbDataAdapter ad = new OleDbDataAdapter("select id, party_name from party_list", con);
            ad.Fill(data);
            con.Close();

            party_list.ItemsSource= data.DefaultView;
            party_list.DisplayMemberPath = "party_name";
            party_list.SelectedValuePath = "id";

            string[] arr = data.AsEnumerable().Select<System.Data.DataRow, String>(x => x.Field<String>("party_name")).ToArray();
            nameList.AddRange(arr);            

        }       

        private void party_list_KeyUp(object sender, KeyEventArgs e)
        {
            party_list.ItemsSource = null;
            var names = from n in nameList where (n.StartsWith(party_list.Text)) select n;

            foreach (string name in names)
            {
                autoList.Add(name.ToString());
            }
            try
            {
                if (party_list.Text.Length > 0)
                {
                   if (autoList.Count > 0)
                   {
                        party_list.ItemsSource = autoList;
                        party_list.IsDropDownOpen = true;

                   }                  
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
当itemssource绑定更改时项目正在更新的位置
但不显示在组合框中

您需要在分配新的参与方列表之前清除。ItemsSource=autoList


但我不建议像这样创建类。并将数据表转换为其类。所以你会有恒常性。

@VashviVekariya Np尝试接受答案,如果有效,我会在一段时间后给出恒常性的一些例子
party_list.DisplayMemberPath = "";
party_list.SelectedValuePath = "";