Caliburn.Micro:没有填充Combobox

时间:2013-05-20 12:35:35

标签: c# wpf combobox caliburn.micro

我有一个带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;
        }
    }

1 个答案:

答案 0 :(得分:2)

您的视图模型属性称为GeorgaphyNames,这是一个错字。

此外,最好在视图中使用x:Name,而不是Name