通常狀況集合的數據綁定都是用ObservableCollection,但今天使用List作數據綁定,發現一個奇怪的問題。函數
描述:插件
List的數據當在插件加載的時候進行數據初始化(經過Add方法),發現界面展現不出來,數據沒有綁定上,當把數據初始化放在構造函數中,就可以正常。code
解決:io
緣由是List在插件加載的時候已經將數據進行綁定了,此時在經過Add是通知不到的,只有藉助中間變量,一次性賦值:class
//old-這樣處理不正確 GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "branch_no", Name = "業務部門" }); GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "trader_id", Name = "交易員" }); GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "operator_no", Name = "下單員" }); GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "prod_account", Name = "項目" }); GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "fund_account", Name = "資金帳號" }); GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "contract_code", Name = "合約代碼" }); GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "entrust_bs", Name = "買賣方向" }); GroupFieldSrc.Add(new NameValue { IsSelected = true, Value = "offset_direction", Name = "開平倉方向" }); //處理方式 List<NameValue>GroupFieldSrc1 = new List<NameValue>(); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "branch_no", Name = "業務部門" }); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "trader_id", Name = "交易員" }); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "operator_no", Name = "下單員" }); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "prod_account", Name = "項目" }); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "fund_account", Name = "資金帳號" }); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "contract_code", Name = "合約代碼" }); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "entrust_bs", Name = "買賣方向" }); GroupFieldSrc1.Add(new NameValue { IsSelected = true, Value = "offset_direction", Name = "開平倉方向" }); GroupFieldSrc = GroupFieldSrc1;
這裏建議使用ObservableCollection變量