I have a ListView with three TextBlock for each Item. The first one has the default color (black) and the others has the property Foreground set to gray.
When I sele
You could achieve what you are trying to do by converting your code from having DataTemplate
for a ListViewItem
to having a ControlTemplate
This is what I tried:
ListViewItem Style:
and then I removed DataTemplate from the ListView
XAML:
However, if you must use DateTemplate
, then what you could do is have a property called IsSelected
on your ViewModel
, ResultatRechercheViewModel
and then have DataTriggers on that property in your DataTemplate
.
Updated DataTemplate:
And, you need to update your ViewModel
code to set IsSelected
property, Below is code from my MainViewModel:
public ResultatRechercheViewModel ResultatSelectione
{
get { return _resultatSelectione; }
set
{
if (_resultatSelectione != null)
{
_resultatSelectione.IsSelected = false;
}
_resultatSelectione = value;
_resultatSelectione.IsSelected = true;
}
}
Hope this resolves your problem or gives you some ideas to resolve your problem.