c# - 'an unhandled exception of type 'System.NullReferenceException' : <p>i'm a newbie in MVVM, I have a Model.cs which contains a few property of 'ID' and 'PositionName' and i got View.cs which contains DataGrid with SelectedItems={Binding Items} and ItemSource={Binding Position} and a button with a Command={Binding SHowEdits} after clicking that i encountered a NullReference error at 'Items.PositionName == null '.<br>
here's my code.</p>

<p><strong>ViewModel.cs</strong></p>

<pre><code>class PositionVM : INotifyPropertyChanged
{
    private ObservableCollection&lt;PositionModel&gt; _position;
    private PositionModel _items;
    private ICommand _showedits;
    public ObservableCollection&lt;PositionModel&gt; Position
    {
        get
        {
            return _position;
        }
        set
        {
            _position = value;
            NotifyProperty("Position");
        }
    }
    public PositionModel Items
    {
        get
        {
            return _items;
        }
        set
        {
            _items = value;
            NotifyProperty("Items");
        }
    }
    public ICommand ShowEdits
    {
        get
        {
            if (_showedits == null)
                _showedits = new ShowEdit();
            return _showedits;
        }
        set
        {
            _showedits = value;
        }
    }
    public PositionVM()
    {
        Position = new ObservableCollection&lt;PositionModel&gt;();
        Position.Add(new PositionModel()
        {
            ID = 1,
            PositionName = "asd"
        });
    }
    public void ShowEditDialog()
    {
        if (Items.PositionName == null)
        {
            MessageBox.Show("ERROR");
        }
        else
        {
            PositionView view = new PositionView();
            Data.ID = view.txtid.Text;
            var z = new PositionView();
            z.ShowDialog();
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyProperty(String info)
    {
        if(PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
}
</code></pre>

<p>Why am i getting this error? and How can i avoid it? Thanksss</p>
