Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
Setting Label Style in Code
posted

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>

 

This style should be set at labels with a activated filter. I try to accomplish this through using the RecordFilterChanged event:

 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 :-(

Parents
  • 69686
    posted

    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>

            </Style>

    WpfApplication13.zip
Reply Children
No Data