0

クライアント オブジェクト モデルを使用して 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));

これを行う方法がわかりません。上記の問題のコードまたはリンクを教えてください。私が何か間違ったことをしているなら、私を導いてください。

4

1 に答える 1

0

行インデックスにビジネス上の意味がある場合は、それをTimeLogクラスに追加するだけです。

TimeLogクラスはを実装する必要がありINotifyPropertyChanged、プロパティはPropertyChangedバインディングが機能するためにイベントを発生させる必要があります(少なくとも最初のバインディングの後で値が変更されている場合)。

行インデックスがセルのレンダリングに影響を与えている理由を説明できますか?特定の行を強調表示する方法ですか?

于 2011-12-15T17:42:04.937 に答える