views:

107

answers:

1

Hi,

We're currently working out how to implement MVVM and I've got to the point where I've got the MVVM Light Toolkit set up in blend and can specify dummy data to be supplied if running in Blend. All good.

I've created a dummy list of data. The list contains 6 instances of a very simple class called DummyItem which has Age and Name properties.

Here's the main code from my 'DummyList' class:

public class DummyItem{

    public string Name;
    public int Age;

    public DummyItem(string name, int age){
        this.Name = name;
        this.Age = age;
    }
}

public class DummyList : ArrayList
{
    public DummyList()
    {
        this.Add(new DummyItem("Dummy1", 00));
        this.Add(new DummyItem("Dummy2", 01));
        this.Add(new DummyItem("Dummy3", 02));
        this.Add(new DummyItem("Dummy4", 03));
        this.Add(new DummyItem("Dummy5", 04));
        this.Add(new DummyItem("Dummy6", 05));
    }
}

Here's the operative part of my XAML. The DataContext line does work and points to the correct ViewModel.

<Grid x:Name="LayoutRoot">
    <ListBox x:Name="ListViewBox"
        DataContext="{Binding Source={StaticResource Locator}, Path=ListViewModel}"
        ItemsSource="{Binding TheList}"
        DisplayMemberPath="Name">
    </ListBox>
</Grid>

The problem is, when I add 'DisplayMemberPath', as I have above, then I can no longer see the list items in Blend. If I remove 'DisplayMemberPath', then I see a list of objects (DummyItem) with their full path. When the app is run, everything works perfectly. It's just that in Blend itself I cannot see the list items when I use 'DisplayMemberPath'.

Anyone know why I can't see the items inside Blend itself when I use DisplayMemberPath?

Thanks!

AT

+1  A: 

Try making Name and Age properties:

public class DummyItem
{  
    public string Name {get; set; }
    public int Age {get; set;}

    public DummyItem(string name, int age)
    { 
        this.Name = name; 
        this.Age = age; 
    } 
}
Adam Barney
Absolutely right. The absence of get; set; means they were not revealed. I didn't realise you had to put get; set; in even if they were empty.Thanks!
Andy T