How to refactor models without breaking WPF views?
- by Tim Murphy
I've just started learning WPF and like the power of databinding it presents; that is ignoring the complexity and confusion for a noob.
My concern is how do you safely refactor your models/viewmodels without breaking the views that use them?
Take the following snippet of a view for example:
<Grid>
<ListView ItemsSource="{Binding Contacts}">
<ListView.View>
<GridView>
<GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}"/>
<GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=FirstName}"/>
<GridViewColumn Header="DOB" DisplayMemberBinding="{Binding Path=DateOfBirth}"/>
<GridViewColumn Header="# Pets" DisplayMemberBinding="{Binding Path=NumberOfPets}"/>
<GridViewColumn Header="Male" DisplayMemberBinding="{Binding Path=IsMale}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
The list is bound to the Contacts property, IList(Of Contact), of the windows DataSource and each of the properties for a Contact is bound to a GridViewColumn.
Now if I change the name of the NumberOfPets property in the Contact model to PetCount the view will break. How do I prevent the view breaking?