クライアント オブジェクト モデルを使用して Silverlight Web パーツを開発しています。次のように、プロジェクトにコンバーターが 1 つあります。
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();
}
}
このコンバーターを使用して、次の要素のバインドを行っています
<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>
次のように TimeLog クラスで定義されたプロパティが 1 つあります。
public SolidColorBrush Foreground {get;set;}
バインディングは私にとってはうまく機能しています。次のように、データグリッドのloadingrowイベントがあります。
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));
}
}
上記のコードの次の行を参照してください
PaidList[index].Foreground = new SolidColorBrush(Color.FromArgb(50, 150, 150, 150));
上記の行では、特定の行インデックスに対して動的に textblok の Foreground プロパティのバインドを行いたいと考えています。この場合、コンバーターが値を取得するようにします(特定の行インデックスに対して次の値を返します)
new SolidColorBrush(Color.FromArgb(50, 150, 150, 150));
これを行う方法がわかりません。上記の問題のコードまたはリンクを教えてください。私が何か間違ったことをしているなら、私を導いてください。