How to refactor models without breaking WPF views?

Posted by Tim Murphy on Stack Overflow See other posts from Stack Overflow or by Tim Murphy
Published on 2010-05-20T08:18:47Z Indexed on 2010/05/20 8:30 UTC
Read the original article Hit count: 197

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about .NET