使用MVVM模式时,WPF组合框在视图中不可见

使用MVVM模式时,WPF组合框在视图中不可见,wpf,mvvm,data-binding,itemscontrol,itemssource,Wpf,Mvvm,Data Binding,Itemscontrol,Itemssource,我使用MVVM模式创建了一个wpf项目。在视图中,当我启动一个项目时,我并没有在组合框和标签中看到任何项,尽管我在调试时在ObservableCollection中的DataContext中看到了项。 我的代码中的绑定有什么问题 我的XAML代码: <ItemsControl ItemsSource="{Binding Items}" > <ItemsControl.ItemTemplate> <DataTemplate>

我使用MVVM模式创建了一个wpf项目。在视图中,当我启动一个项目时,我并没有在组合框和标签中看到任何项,尽管我在调试时在ObservableCollection中的DataContext中看到了项。 我的代码中的绑定有什么问题

我的XAML代码:

<ItemsControl ItemsSource="{Binding Items}" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"  />
                        <ColumnDefinition Width="*"  />
                    </Grid.ColumnDefinitions>
                    <Label  Content="{Binding Name}" Grid.Column="0" Height="26" Width="105" Margin="5,5,0.2,0"/>
                    <ComboBox  ItemsSource="{Binding ComboBoxItems}" Grid.Column="1" />
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
ViewModel.cs代码:

public ObservableCollection<Model> Items;
public ViewModel()
    {
        Items = new ObservableCollection<Model>();
        Items.Add(new Model { Name = "111111" });
        Items.Add(new Model { Name = "222222" });
        Items.Add(new Model { Name = "444444" });
        Items.Add(new Model { Name = "333333" });
    }
型号代码:

    public class Model : INotifyPropertyChanged
        {
    public ObservableCollection<string> ComboBoxItems;

    public Model()
            {
                   ComboBoxItems =new ObservableCollection<string>();
                   ComboBoxItems.Add("111111");
                   ComboBoxItems.Add("222222");
                   ComboBoxItems.Add("444444");
                   ComboBoxItems.Add("333333");
            }
private string _name;
    public string Name
            {
                get { return _name; }
               set
               {
                  _name= value;
                  OnPropertyChanged("Name");
               }
            }
    public void OnPropertyChanged([CallerMemberName]string prop = "")
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(prop));
            }
  public event PropertyChangedEventHandler PropertyChanged;
       }

要使绑定工作,您需要属性

更改变量

 public ObservableCollection<string> ComboBoxItems;
财产

 public ObservableCollection<string> ComboBoxItems {get;set;}
类似项目

public ObservableCollection<Model> Items;

您可能希望在setter中更改这些propfull和raise属性

但是属性有getter和setter


变量不绑定,也不会绑定。

ComboBoxItems不是公共属性。您需要绑定一个公共属性。非常感谢您的回复!
public ObservableCollection<Model> Items;
  public ObservableCollection<Model> Items  {get;set;}