概述: 我已经设置了ComoboBox绑定到List属性。但是当我运行该应用程序时,组合框中没有填充数据。如何解析ComboBox上的空绑定?
调试步骤:
- 我检查了输出窗口绑定错误,告诉我说,数据源可能为空。
- 然后我在QueryList属性的setter上设置一个断点。这表明列表计数为0.看起来在调用setter之后执行对init的调用。
我的想法是列表被调用setter后被初始化。这意味着在该阶段绑定将在组合框上被调用时绑定将为空。
问:
我怎样才能调用init方法之前QueryList二传手我的名单被称为?
代码片段:
后面的代码 -
//The binding property for the combo box
private List<string> _queryList;
public List<string> QueryList
{
get
{
return this._queryList;
}
set
{
this._queryList = value;
}
}
public MainWindow()
{
InitializeComponent();
// Establish the Login control
Ctrl = new CrmLogin();
QueryList = new List<string>();
InitQueryList();
}
//Call to init the list data
private void InitQueryList()
{
_queryList.Add("Query queues with unapproved email routers");
_queryList.Add("Query queues with emails in pending send status");
}
组合框结合设置 -
<ComboBox HorizontalAlignment="Left" ItemsSource="{Binding QueryList}" Grid.Column="1" x:Name="queryComboBox" Grid.Row="0" VerticalAlignment="Bottom" Width="300" Visibility="Collapsed" Text="Select a query"/>
你有没有尝试过在构造函数的末尾调用InitializeComponent()? – Breeze
尝试使用ObservableCollection而不是列表 – Taterhead