0
votes

I have a viewModel which consists of a class and an Observable collection

class MyViewModel
{
    public string SomeName {set; get;};
    public ObservableCollection<ItemName> ItemNames {set; get;}
} 

In the Page i am setting the DataContext of the page itself to this object i.e.

MyViewModel myModel = new MyViewModel("111");
this.DataContext = myModel;

Then i have a ListView in the page design which references to the datacontext, and i can get the value from it using the ItemSource property

<ListView
....
ItemsSource="{Binding Path=ItemNames}">

However, within this ListView, how do i access the "SomeName" Property?

2

2 Answers

0
votes

A ListView needs definition for columns. Each column can be bound to a different property.

In your case:

<ListView 
....
ItemsSource="{Binding Path=ItemNames}">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="The Name" DisplayMemberBinding="{Binding SomeName}" />
        </GridView>
    </ListView.View>
</ListView>
0
votes

I am using WinRT, and the way I found it to work was by setting the source to 'Binding' and then give the Path to the Object

Text="{Binding Source={Binding}, Path=SomeName}"