I want to allow the user to add rows in a datagrid. I know the Datagridview from WinForms and there is allways on the bottom of the Datagrid a empty line that i can fill with data.
<DataGrid x:Name="dgv"
Grid.ColumnSpan="4"
Grid.Row="1"
CanUserAddRows="True"
CanUserDeleteRows="True"
SelectionUnit="FullRow"
AutoGenerateColumns="False"
ItemsSource="{Binding Entries}">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Anrede" Width="1*"></DataGridComboBoxColumn>
<DataGridTextColumn Header="Vorname" Width="2*" Binding="{Binding Vorname}" />
<DataGridTextColumn Header="Nachname" Width="2*" Binding="{Binding Nachname}" />
</DataGrid.Columns>
</DataGrid>
Code behind:
public ObservableCollection<Mitreisender> Entries { get; }
public aufenthaltsWindow()
{
InitializeComponent();
Entries = new ObservableCollection<Mitreisender>();
}
The Class
public class Mitreisender
{
public int MitreisenderID { get; set; }
public Gast.AnredeTyp Anrede { get; set; }
public string Titel { get; set; }
public string Vorname { get; set; }
public string Nachname { get; set; }
public virtual Aufenthalt Aufenthalt { get; set; }
public Mitreisender()
{
}
}