Hello,
I need a little assistance. I created a Style as DynamicResource which I am loading in a private variable at startup:
Normal 0 21 false false false DE X-NONE X-NONE <Style x:Key="LabelPresenterStyleFiltered" TargetType="{x:Type igDP:LabelPresenter}" >
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Offset="0" Color="#FFfffadc"/>
<GradientStop Offset="1" Color="#FFffda5b"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
private void EvaluationList_RecordFilterChanged(object sender, Infragistics.Windows.DataPresenter.Events.RecordFilterChangedEventArgs e) { RecordFilter updatedRecordFilter = e.RecordFilter; if (updatedRecordFilter.Conditions.Count == 0) { updatedRecordFilter.Field.Settings.LabelPresenterStyle = null; } StringBuilder sb = new StringBuilder(2000); sb.Append(ResourcesManager.GetResource("Evaluation")); RecordFilterCollection recordFilters = this.EvaluationListUI.EvaluationList.FieldLayouts[0].RecordFilters; Boolean isFiltered = false; if (recordFilters.Count > 0) { sb.Append(ResourcesManager.GetResource("EvaluationMskFiltered")); foreach (RecordFilter recordFilter in this.EvaluationListUI.EvaluationList.FieldLayouts[0].RecordFilters) { if (recordFilter.Conditions.Count > 0) { sb.Append(recordFilter.Field.Label).Append(","); isFiltered = true; recordFilter.Field.Settings.LabelPresenterStyle = this.ActiveFilterLabelStyle; } else { recordFilter.Field.Settings.LabelPresenterStyle = null; } } sb.Remove(sb.Length - 1, 1); sb.Append(" )"); } if (isFiltered) { this.EvaluationListUI.Label = sb.ToString(); } else { this.EvaluationListUI.Label = ResourcesManager.GetResource("Evaluation"); } }
The style does not show up :-(
Hello,This is because the element has to be reinitialized. However, you can go with a different approach and avoid this. You can create an attached property on the MainWindow and bind to this. I am attaching a sample project demonstrating this approach. Here are some code snippets from the sample :
1. create attached property of the main window :
public static bool GetIsFiltered(DependencyObject obj)
{
return (bool)obj.GetValue(IsFilteredProperty);
}
public static void SetIsFiltered(DependencyObject obj, bool value)
obj.SetValue(IsFilteredProperty, value);
public static readonly DependencyProperty IsFilteredProperty =
DependencyProperty.RegisterAttached("IsFiltered", typeof(bool), typeof(MainWindow), new UIPropertyMetadata((bool)false));
2. Set it to the Field appropriately :
private void xamDataGrid1_RecordFilterChanged(object sender, RecordFilterChangedEventArgs e)
if (e.RecordFilter.Conditions.Count > 0)
e.RecordFilter.Field.SetValue(IsFilteredProperty, true);
else
e.RecordFilter.Field.SetValue(IsFilteredProperty, false);
3. Apply a style that binds to this property :
<Style TargetType="{x:Type igDP:LabelPresenter}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=(Field).(local:MainWindow.IsFiltered), RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
Hi Alex, thanks for the help, much appreciated.
I got this working with a demo, but not in my project. My "MainWindow" is a UserControl, should this be a problem? I can't see what I am doing wrong right now..
EDIT: Okay, just tested it and works fine with a User Control in a Demo, too. So I'm still stuck here :-/
Do you have any binding errors in the output? Can you put together a small project that reproduces the issue so that we can look into?