Hi
I have one question. How can I highlight an item from ViewModel? I have simple MVVM scenario:
In View I bind ItemSource to FooCollection, I am binding the SelectedItem of the RadListBox to SelectedFoo from VM and I have two TextBlocks to display the SelectedFoo. I have one button to Add a new Item to the Collection and setting the SelectedFoo to this new Item from Collection. Everything is fine, the two textblocks shows correct data, but the RadListBox is not highlighting the new Item Added to the collection. The collection rebinds fine because I can see the added item in list, but it is not highlighted.
Am I doing something wrong?? I tried to set the SelectedValue, SelectedValuePath, SelectedItem. I have google it a lot but no luck.
Thanks Vitalij
I have one question. How can I highlight an item from ViewModel? I have simple MVVM scenario:
public
class
FooViewModel : ViewModelBase
{
private
ObservableCollection<Foo> _fooCollection;
private
Foo _selectedFoo;
private
ICommand _addCommand;
public
ObservableCollection<Foo> FooCollection
{
get
{
return
_fooCollection; }
set
{
_fooCollection = value;
OnPropertyChanged(
"FooCollection"
);
}
}
public
Foo SelectedFoo
{
get
{
return
_selectedFoo; }
set
{
_selectedFoo = value;
OnPropertyChanged(
"SelectedFoo"
);
}
}
public
ICommand AddCommand
{
get
{
return
_addCommand ?? (_addCommand =
new
RelayCommand(i=>
this
.AddCommandMethod())); }
}
private
void
AddCommandMethod()
{
//Add item to collection
//Add item to SelectedFoo
}
In View I bind ItemSource to FooCollection, I am binding the SelectedItem of the RadListBox to SelectedFoo from VM and I have two TextBlocks to display the SelectedFoo. I have one button to Add a new Item to the Collection and setting the SelectedFoo to this new Item from Collection. Everything is fine, the two textblocks shows correct data, but the RadListBox is not highlighting the new Item Added to the collection. The collection rebinds fine because I can see the added item in list, but it is not highlighted.
Am I doing something wrong?? I tried to set the SelectedValue, SelectedValuePath, SelectedItem. I have google it a lot but no luck.
Thanks Vitalij