Is the DocumentViewModelList
a property of your DocumentViewModel
?
Typically, what I would have is a ViewModel for that window which would expose an ObservableCollection<T>
where T
is what you want displayed in the list. Then, you can assign the Window/Page/etc.'s DataContext
to the ViewModel, and then bind the ItemsSource
of the ListBox
to that ObservableCollection<T>
property.
For example, here would be a snippet of my ViewModel.
public class SomeViewModel
{
public ObservableCollection<SingleDocumentViewModel> Docs {get; private set; }
// other properties can go here
}
In the code-behind for the XAML, (I usually do it in the constructor), you can set its DataContext
to a new instance of your ViewModel
public AwesomeDocumentList()
{
this.DataContext = new SomeViewModel();
// the rest of the constructor
}
With the Window's DataContext set, you can bind the ItemsSource
to the exposed property (I called it Docs
)
<ListBox ItemsSource="{Binding Docs}" ... />
Hope that helps.
Update
In the RelayCommand
for the button, do you have something specified for the CanExecute
predicate? If not, then I believe the RelayCommand
will default to always enabled. But if you have a predicate specified, take a look in there.
The code you posted for the IsSelected
property looks fine. Looks like the problem lies elsewhere.