각 레벨마다 다른 FieldLayout이있는 경우 변환기를 사용하여 DataRecordPresenter를 대상으로하는 단일 스타일을 사용하여 배경을 설정할 수 있습니다.
XAML :
<local:BackgroundConverter x:Key="BackgroundConverter"/>
<Style TargetType="{x:Type igDP:DataRecordPresenter}">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=FieldLayout.Key, Converter={StaticResource BackgroundConverter}}"/>
</Style>
변환기 :
public class BackgroundConverter:IValueConverter
{
public BackgroundConverter()
{
this.Brushes = new Dictionary<string, Brush>();
}
public Dictionary<string, Brush> Brushes {get;set;}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is string)
{
string key = value.ToString();
if (this.Brushes.ContainsKey(key))
return this.Brushes[value.ToString()];
}
return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
키 1 필드 및 키 2에 사용할 색상을 설정합니다 다음 :
BackgroundConverter backgroundConverter = this.Resources["BackgroundConverter"] as BackgroundConverter;
backgroundConverter.Brushes.Add("Key1", Brushes.Green);
backgroundConverter.Brushes.Add("Key2", Brushes.Yellow);
것은 같은를 재사용하는 경우 FieldLayout을 여러 필드에 사용하면 InitializeRecord 이벤트를 사용하고 스타일을 bin으로 변경할 수 있습니다.
XAML :
<Style TargetType="{x:Type igDP:DataRecordPresenter}">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=Record.Tag}"/>
</Style>
C 번호 :
void XamDataGrid1_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
{
if (!e.ReInitialize)
{
// Set the tag to the desired brush.
e.Record.Tag = Brushes.Blue;
}
}
내가 사용하는 브러시를 결정하는 조건부 논리를 추가하지 않은 참고하고이 같은 DataRecord의 태그에 D 서로 다른 배경을 가지기 위해서는 여전히 다른 레벨을 위해해야합니다.