开发者

Unable to get DataGrid working with ObservableCollection

开发者 https://www.devze.com 2023-01-19 18:30 出处:网络
Everything compiles, but at run time a blank row is displayed. If I try to edit an entry, it says \"No XPath set\". What am I doing wrong? I tried a ton of variations, not having the INotifyPropertyCh

Everything compiles, but at run time a blank row is displayed. If I try to edit an entry, it says "No XPath set". What am I doing wrong? I tried a ton of variations, not having the INotifyPropertyChanged interface etc.

The base class is:

public class Variable : INotifyPropertyChanged 
    {
        public string Name;
        public string Value;

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }

The observable collection is:

 public class VariableCollection:ObservableCollection<Variable>
    {
         public VariableCollection()
            : base()
        {
        }

         public VariableCollection(List<Variable> list)
            : base(list)
        {
        }
    }

The binding is:

public VariablesView(VariableCollection variables)
        {
            InitializeComponent();

            gridContent.ItemsSource = variables;
        }   

The XAML is:

<DataGrid Name="gridContent" AutoGenerateColumns="False">
      开发者_JS百科      <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Name}" Header="Name" />
                <DataGridTextColumn Binding="{Binding Value}" Header="Value" />
            </DataGrid.Columns>
        </DataGrid>


That is simple. You have fields in your class instead of properties.

Change the code to:

    public string Name{ get; set;}
    public string Value{ get; set;}
0

精彩评论

暂无评论...
验证码 换一张
取 消