这份原稿.微:组合框没有被填充
本文关键字:填充 组合 | 更新日期: 2023-09-27 18:14:41
我有一个WPF应用程序与Caliburn.Micro。我试图填充我刚刚添加的新组合框,但它保持空,尽管同一视图上的其他组合框已填充。我进行了调试,因此我知道ViewModel中的GeorgaphyNames源集合是正确填充的。你能帮帮我吗?
下面是我的代码:模型:
public class GeographyName : PropertyChangedBase
{
private string _name;
public string Name
{
get { return _name; }
set
{
if (_name == value) return;
_name = value;
NotifyOfPropertyChange(() => Name);
}
}
...
}
视图:
<ComboBox Grid.Row="6" Grid.Column="1" Name="GeographyNames" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedItem="SelectedGeographyName" Style="{StaticResource DetailCombo}" />
ViewModel:
private BindableCollection<GeographyName> _geographyNames;
public BindableCollection<GeographyName> GeorgaphyNames
{
get { return _geographyNames; }
private set
{
if (_geographyNames == value)
return;
_geographyNames = value;
NotifyOfPropertyChange(() => GeorgaphyNames);
}
}
private GeographyName _selectedGeographyName;
public GeographyName SelectedGeographyName
{
get { return _selectedGeographyName; }
set
{
if (_selectedGeographyName == value)
return;
_selectedGeographyName = value;
NotifyOfPropertyChange(() => SelectedGeographyName);
IsModified = true;
}
}
在更改另一个组合框中的选择时填充该组合框:
private Ldc _selectedLdc;
public Ldc SelectedLdc
{
get { return _selectedLdc; }
set
{
if (_selectedLdc == value)
return;
_selectedLdc = value;
NotifyOfPropertyChange(() => SelectedLdc);
if (SelectedLdc != null)
{
GeorgaphyNames = GeographyName.GetData(SelectedLdc.LdcId);
}
IsModified = true;
}
}
你的视图模型属性叫做GeorgaphyNames
,这是一个错别字。
另外,在你的视图中最好使用x:Name
,而不是Name
。