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
170
How to Style XamCheckEditor for Null Value and ReadOnly
posted

Default style fore Null Value is grey check in XamCheckEditor. How can I change it to show null value as unchecked(false value)?

When XamCheckEditor value is True and IsReadOnly=True, it appears exactly the same way as Null Value(grey check), which is very confusing. How can I change it to Grey background with Black Check instead?

Parents
No Data
Reply
  • 4475
    Verified Answer
    posted

    Hello,


    I have been investigating into your issue and I do understand your concern. In order to achieve the desired behavior could re-template the xamCheckEditors default template, by placing the new modified ControlTemplate in a style. This style will be triggered when the Value property becomes Null. Since the default template is using a ValueEditorCheckBox,  we can bind the IsChecked property of that control  to the corresponding parents property including one important feature– we can put a value converter in order to catch the null value and return false. With that custom technique the controls Value property will remains Null, but the inner ValueEditorCheckBox would not be checked. That means the xamCheckEditor will never show the blue square that marks the Indeterminate state.

     

    Here is a corresponding sample:

     

    Xaml part

     

    <local:TriggersConverter x:Key="someRes"/>

     

      <Style TargetType="{x:Type igEditors:XamCheckEditor}">

                    <Style.Triggers>

                        <Trigger Property="Value" Value="{x:Null}">

                            <Setter Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type igEditors:XamCheckEditor}">

                                        <Border x:Name="MainBorder"

                                                BorderBrush="{TemplateBinding BorderBrush}"

                                                BorderThickness="{TemplateBinding BorderThickness}"

                                                   Background="{TemplateBinding Background}">

                                            <!-- SSP 10/3/07 BR25672 Added Padding="{TemplateBinding Padding}" to the ValueEditorCheckBox below -->

                                            <igEditors:ValueEditorCheckBox x:Name="PART_FocusSite"

                                                          IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource kkk}, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

                                                          IsThreeState="{TemplateBinding IsThreeState}"

                                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

                                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

                                                          Margin="{TemplateBinding Padding}"/>

                                     </Border>

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                    </Style.Triggers>

                </Style>

     

     

    Code behind part:

     

    public class TriggersConverter : IValueConverter

        {

            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

            {

                if (value == null)

                {

                    return false;

                }

     

                return true;

            }

     

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

            {

                return value;

            }

        }

     

    In case of other concerns on that matter please do not hesitate to ask.

     

    Sincerely,

    Ekaterina

    Developer Support Engineer

    Infragistics Inc.

    www.infragistics.com/support

     

     

Children