I see two questions here and I'll try to answer them step by step.
Binding list of items with detail view
Given these ViewModel classes (imagine everyone implements INotifyPRopertyChanged
):
public class DataView {
public Item SelectedItem {get; set; }
public List<Item> Items { get; private set; }
}
public class Item {
public string Title { get; set; }
}
Putting a Data
instance into the DataContext
, a minimal View might look like this:
<StackPanel>
<ListView Items="{Binding Items}" SelectedItem="{Binding SelectedItem}" />
<TextBox Text="{Binding SelectedItem.SelectedItem.Title}" />
</StackPanel>
Adding new items
To be able to create a new Item
without immediately adding it to the list, you might want to split off the newly created object into its own area. Visually you can either have it in a new pop up or integrated into the list, but actually it'll be only added to the list on the next try to add or acknowledge the parent dialog. At this point you can also verify whether the Item
is valid enough to add it to the list.