How to add textbox values to list using MVVM?
<p>Models</p>

<pre><code>public class EmployeeDetails
{
    public string Name { get; set; } 
    public int Age {get;set;}
} 

public class AddressDetails
{
    public EmployeeDetails EmployeeName { get; set; }
    public string City { get; set; }
} 
</code></pre>

<p>View</p>

<pre><code>&lt;Window x:Class="ClassCollection.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:ClassCollection"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525"
    DataContext="{Binding Source={StaticResource loc},Path=ViewModel}"
    &gt;
&lt;Grid&gt;
    &lt;StackPanel Margin="0 20 0 0"&gt;
        &lt;TextBox x:Name="txt1" Width="90" Height="20" Text="{Binding Details.EmployeeName}"/&gt;
        &lt;TextBox x:Name="txt2" Width="90" Height="20" Text="{Binding Details.City}"  Margin="0 20 0 0"/&gt;
    &lt;/StackPanel&gt;
    &lt;Button x:Name="btn" Width="90" Height="25" Content="Add" Command="  {Binding AddCommand}"/&gt;
&lt;/Grid&gt;
&lt;/Window&gt;
</code></pre>

<p>ViewModel</p>

<pre><code>public class Viewmodel
{
    public ObservableCollection&lt;AddressDetails&gt; EmployeeList;
    public Viewmodel()
    {
        EmployeeList = new ObservableCollection&lt;AddressDetails&gt;();
        LoadCommand();
    }

    private AddressDetails _details;
    public AddressDetails Details
    {
        get { return _details; }
        set
        {
            _details = value;
        }
    }

    // Commands
    public ICommand AddCommand { get; set; }

    private void LoadCommand()
    {
        AddCommand = new CustomCommand(Add, CanAdd);
    }

    private bool CanAdd(object obj)
    {
        return true;
    }

    private void Add(object obj)
    {
        EmployeeList.Add(new AddressDetails { EmployeeName = Details.EmployeeName, City = Details.City });
    }
}
</code></pre>

<p>Locator</p>

<pre><code>public class Locator
{
    private static Viewmodel viewmodel = new Viewmodel();
    public static Viewmodel ViewModel
    {
        get { return viewmodel; }
    }
}
</code></pre>

<p>How to add <code>TextBox</code> value to collection list using MVVM?</p>

<p>The Above is my code that I have tried. It shows null reference exception if I do like above. What would be the problem?</p>

<h1>Update</h1>

<p>I have two fields in <code>EmployeeDetails</code> class. So I must give input for these two field when add to collection. But I need only one field <code>Name</code> to insert to the collection. How to do it?</p>