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
275
Multi Selection with theme Office2k7Silver
posted

Hi,

I am setting the theme Office2k7Silver in the code. When we have single record selected it decorate the row with redish golden color (or soething similar). But when I have multiple records selected, it doesn't style the records same fashion. Shouldn't these records also have same style set?

Can some one let me know how to set this through code?

 

  • 2677
    posted

    Hello DarkestDevil,

    This issue that you see is the theme having an active style and a Selected style.  The active one is the red orange color and the selected is the silver which complies with the office silver theme.  However, if you wnat to change one piece of the them, you will run into a limitation of the WPF framework.  When you apply a style for a particular themed element, it will take that style and not the theme.  However, I have a workaround for you.  I will show you how to do this in code and in xaml.

    In Code:

               1 Style style = new System.Windows.Style(typeof(DataRecordCellArea));
               2 style.BasedOn = Infragistics.Windows.Themes.DataPresenterOffice2k7Silver.DataRecordCellArea;
               3 LinearGradientBrush lgb = (LinearGradientBrush)this.LayoutRoot.TryFindResource("NewSelectBrush");
               4 style.Setters.Add(new Setter(DataRecordCellArea.BackgroundSelectedProperty, lgb));
               5 this.xamDataGrid1.FieldLayouts[0].Settings.DataRecordCellAreaStyle = style;

    then inside of Grid.Resources, add the LinearGradientBrush as a resource.  You can do this all in code, but then conversions are needed to convert hex values to colors.  So, I just grabbed it from a resource as you can see line 3.  The main thing to get around the issue is the BasedOn property.  This is the way we get around the issue.  Infragistics exposes static Properties so the developer can leverage them.  you can see that in line 2.  Then it is just applying the style.   The linear gradient brush is below.

    <LinearGradientBrush x:Key="NewSelectBrush" StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="#FFFBDBB5" Offset="0"/>
                    <GradientStop Color="#FFFEC778" Offset="0.49900001287460327"/>
                    <GradientStop Color="#FEB456" Offset="0.5"/>
                    <GradientStop Color="#FFFDEB9F" Offset="1"/>
                </LinearGradientBrush>

    If you want to do it in xaml, but the style inside of the XamDataGrid.Resources.

    <igDP:XamDataGrid.Resources>
                    <Style TargetType="{x:Type igDP:DataRecordCellArea}" BasedOn="{x:Static igThemes:DataPresenterOffice2k7Silver.DataRecordCellArea}">
                        <Setter Property="BackgroundSelected" >
                            <Setter.Value>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStop Color="#FFFBDBB5" Offset="0"/>
                                    <GradientStop Color="#FFFEC778" Offset="0.49900001287460327"/>
                                    <GradientStop Color="#FEB456" Offset="0.5"/>
                                    <GradientStop Color="#FFFDEB9F" Offset="1"/>
                                </LinearGradientBrush>
                            </Setter.Value>
                           
                        </Setter>
                    </Style>
                </igDP:XamDataGrid.Resources>

     

    It is all the same code and it uses the BasedOn workaround.  The linearGradientbrush in the style is the one used for the active color.