MVVM: Bind ListView.SelectedItem.Property to VM Property

I am using the following ListView:

<ListView DataContext="{StaticResource mainViewModel}" ItemsSource="{Binding Items.View}" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding Path=CurrentFile, Source={StaticResource anotherViewModel}, Mode=OneWayToSource}">
            <GridViewColumn Header="File Path" DisplayMemberBinding="{Binding FilePath}" />
            <GridViewColumn Header="Creation" DisplayMemberBinding="{Binding CreationDate}" />

I am binding the ListView (of "File" objects) to one ViewModel and the SelectedItem to a "File" object on another ViewModel. This works fine but now I need to not bind the whole object, but one property. I.e. instead of something like SelectedItem="{Binding Path=CurrentFile I need SelectedItem.FilePath="{Binding Path=FilePath. Is this possible or does SelectedItem binding have to map to the same object type of the ListView collection?


SelectedItem must point to an object present in the ItemsSource. You need to look at SelectedValue and SelectedValuePath for your scenario.

Need Your Help

C# integer masking into byte array

c# arrays byte masking

I'm confused as to why this isn't working, can someone please provide some insight?

Linq to SQL: How do I stop the auto generated object name from being renamed?

sql linq linq-to-sql

In visual studio 2008, when I drag a database table into my dbml screen, any tables that end with the letter s automatcially get the s removed from the dbml object. Is there any way to disable thi...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.