Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何对使用转换器的元素进行动态绑定?_C#_Silverlight_Converter_Dynamic Binding - Fatal编程技术网

C# 如何对使用转换器的元素进行动态绑定?

C# 如何对使用转换器的元素进行动态绑定?,c#,silverlight,converter,dynamic-binding,C#,Silverlight,Converter,Dynamic Binding,我正在使用客户机对象模型开发silverlight web部件。我的项目中有一个转换器,如下所示 public class ForeGroundConverter : IValueConverter { public ForeGroundConverter() { } public object Convert(object value, Type targetType, object parameter,

我正在使用客户机对象模型开发silverlight web部件。我的项目中有一个转换器,如下所示

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();
        }

    }
public SolidColorBrush Foreground {get;set;}
我使用这个转换器为以下元素进行绑定

<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>
装订对我来说很好。现在我有一个datagrid的loadingrow事件,如下所示

SummaryDataGrid\u加载行

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));
                    }

}
请参见上面代码中的以下行

PaidList[index].Foreground = new SolidColorBrush(Color.FromArgb(50, 150, 150, 150));
在上面的一行中,我想为特定的行索引动态绑定textblok的前台属性。在这种情况下,我希望转换器将该值作为(为particualr行索引返回以下值)


我不知道该怎么做。你能为我提供关于上述问题的任何代码或链接吗?如果我做错了什么,请指导我。

如果行索引具有业务意义,我只需将其添加到您的
TimeLog
类中即可

TimeLog
类必须实现
INotifyPropertyChanged
,并且属性必须引发
PropertyChanged
事件才能使绑定工作(至少在第一次绑定后其值发生更改时是如此)


您能解释一下为什么行索引会影响单元渲染吗?这是突出显示给定行的一种方式吗?

我建议您坚持使用业务对象,而不要使用行索引。你能让你的一个对象属性负责保持索引,然后绑定到它吗?
new SolidColorBrush(Color.FromArgb(50, 150, 150, 150));