我有一个带有 Caliburn.Micro 的 WPF 应用程序。我正在尝试填充我刚刚添加的新组合框,但它保持为空,尽管同一视图上的其他组合框已填充。我进行了调试,所以我知道 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}" />
视图模型:
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;
}
}