Hi all,
I'm using CollectionViewSource as in the MVVM Video series as such;
<CollectionViewSource x:Key="basicDataLayoutViewModelViewSource" d:DesignSource="{d:DesignInstance my:BasicDataLayoutViewModel, CreateList=True}" />
.
<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource basicDataLayoutViewModelViewSource}}">
My controller class knows view , but don't know how to extract CurrentItem of CollectionViewSource,which is actually binded viewmodel from known view. It looks simple at first but makes me scratching my head.
Thank you in advance.
HK.lee
In XAML it is {Binding Path=CurrentItem} or (WPF only) {Binding Path=/}.
In code it is harder if I remember right, as you need to cast the CVS to an underlying interface type to get at the CurrentItem property.
But your viewmodel should never contain such code - because that would create a strongly typed awareness of the view from the viewmodel - bad!
So you are better off having a property on your viewmodel called CurrentItem (or something like that), and binding it to the current item using a binding expression in the XAML.
Thank you for your reply, Rocky.
As I'm using MEF in this case, my controller class can grab related viewmodel from active view in region and can dynamically set CanXXX state of toolbar button. I think I have to understand deeper regarding collectionviewsource and currentitem.
Thank you.
HK.Lee
Copyright (c) Marimer LLC