I have a List<Customers>
and I need to find the 开发者_StackOverflow中文版row in a datagrid that contains the Customer's ID and change the background color.
How do I achieve this using Silverlight 4?
In c#, you need to implement the INotifyPropertyChanged
interface on your Customer object, then add a boolean Selected
property.
In the XAML, use data binding to associate the row background color to the Selected property. You can achieve this either with triggers (that are limited in Silverlight compared to WPF) or use a converter:
<Grid Background="{Binding Selected, Converter={StaticResource BoolToColorConverter}}">
The converter is a IValueConverter class taking a boolean and returning a SolidColorBrush
.
精彩评论