0

I am developing silverlight web part using client object model. I have one converter in my project as follows

public class ForeGroundConverter : IValueConverter
    {
        public ForeGroundConverter()
        {
            }
        public object Convert(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            //return "";
            SolidColorBrush result = new SolidColorBrush(Colors.Black);

            return result;
        }

        // No need to implement converting back on a one-way binding 
        public object ConvertBack(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

    }

I am using this converter to do binding for the following element

<sdk:DataGridTemplateColumn SortMemberPath="ClientName"  Header="Client Name" IsReadOnly="True" >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ClientName}" Foreground="{Binding Foreground, Converter={StaticResource ForegroundConverter}}"></TextBlock>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>                        
                    </sdk:DataGridTemplateColumn>

I have one property defined in TimeLog class as follows

public SolidColorBrush Foreground {get;set;}

The binding is working fine for me. Now I have a loadingrow event for datagrid as follows.

SummaryDataGrid_LoadingRow

private void SummaryDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {

if (PaidList.Contains(timeLogObj))
                    {
                        int index = PaidList.IndexOf(timeLogObj);
                        PaidList[index].IsEnabled = false;
                        PaidList[index].CheckBoxVisibility = Visibility.Collapsed;
                        PaidList[index].Foreground = new SolidColorBrush(Color.FromArgb(50, 150, 150, 150));
                    }

}

Please see the following line in above code

PaidList[index].Foreground = new SolidColorBrush(Color.FromArgb(50, 150, 150, 150));

In the above line I want to do the binding for Foreground property of textblok dynamically for particular row index. In this case I want the converter to take the value as (return the following value for particualr row index)

new SolidColorBrush(Color.FromArgb(50, 150, 150, 150));

I am not aware how to do this. Can you please provide me any code or link for the above issue ? If I am doing anything wrong then please guide me.

Shailesh Jaiswal
  • 3,606
  • 13
  • 73
  • 124
  • I would suggest to stick with your business object and not to use Row index. Can you make you one of your object properties resposible for keeping that Index and then bind to it? –  Dec 15 '11 at 17:03

1 Answers1

0

If the row index has a business meaning I would simply add it to your TimeLog class.

The TimeLog class must implement the INotifyPropertyChanged and your properties must raise the PropertyChanged event for your binding to work (at least if their values are changing after the first binding).

Could you explain why the row index is influencing the cell rendering? Is it a way to highlight a given row?

Mart
  • 5,608
  • 3
  • 32
  • 45