Hi, i would like to create new style to the xamGrid.
I have taken the original styles from Blend, and copied the to my solution style file.
I don't want to change nothing on the original styles (I want them to stay as main style of my default grid in the system).
So i have created second copy for each style and Data Template from the original grid and added a "x:Key" to each.
What i want to achieve in mY new style is:
1) To change the background color of all grid headers to silver (including the row numbers header).
2) To change the color of the grid rows (one Blue, the second Red, for all rows on the grid..)
3) To change the color on run time for each Row that selected, and to each row that mouse just hover it.
I think i have found the Data Template that responsible of the headers background color, but i now know which property in the grid's main style i need to change it's style to look at the key of the changed Data Template..
Can you please add an solution example that achieving all my goals?
Itsik
Hello Itsik,
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want.
1) I created a Style for the HeaderCellControl and RowSelectorHeaderCellControl and set their Background to Silver.
2) I copied the default Style of the CellControl and changed the Brushes that are used for the regular (CellItemNormalBackgroundBrush) and alternated CellItemAltNormalBackgroundBrush color. I do the same for the RowSelectorCellControl as well.
3) Change the colors for Selected (CellItemSelectedBackgroundBrush) and Hover (CellRowHoverBackgroundBrush)
Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
Hi Stefan, Thank you for the sample!
Sorry maybe i didn't explained my self correctly..
I already have a styles with target Types: "HeaderCellControl" and "rowSelectorHeaderCellControl" and CellControl..
I don't want to change them, since i want them to be used on my default grid style of the system.
What i wish, Is to to create a second style for the grid (and not override the exists..)
i suppose (please correct me if i wrong..) that the only way to achieve that, Is to make another copy of each of those styles and give each a x:key (since i want them to used only on my new grid style), and then i need to create the second copy of the main grid style itself (with target type "XamGrid") and give him a x:key (let say "MyNewGridStyle"). and then to "bind" all the new styles to that main style.
i think that the final usage supposed to be like that:
<ig:XamGrid ItemSource="{Binding}" Style={StaticResource MyNewGridStyle}>
My problem is that i don't know how to "tell" the style "MyNewGridStyle" to reference it's properties the new styles i have created for HeaderCellControl and RowSelectorHeaderCellControl. etc.. otherwise it would still continue to see the default styles and not the new ones..
(in another words, How to bind "MyNewHeaderCellControlStyle" style and "MyNewRowSelectorHeaderCellControlStyle" to the main style "MyNewGridStyle")
Can you please give me solution example for that?
Thanks
I have been looking into your question and I can suggest you use the Style's BasedOn Property in order to achieve the functionality you want. Here you can read more about it:
http://msdn.microsoft.com/en-us/library/system.windows.style.basedon(v=vs.110).aspx
Please let me know if you need further clarifications on this matter.
Hi again Stefan.
I have read the article, but i don't understand how to use Basedon to achieve my goals.
I have created a new style that based on the original grid style:
<Style x:Key=MyNewGridStyle BasedOn="{StaticResource {x:Type ig:XamGrid}}" TargetType="{x:Type ig:XamGrid}"/>
Then, i have created new styles that based on igPrim:HeaderCellControl and igPrim:RowSelectorHeaderCellControl:
<Style x:Key=MyNewHeaderCellStyle BasedOn="{StaticResource {x:Type igPrim:HeaderCellControl}}" TargetType="{x:Type igPrim:HeaderCellControl}"> <Setter Property="Background" Value="Silver"/> </Style>
<Style x:Key=MyNewHRowSelectorHeaderCellStyle BasedOn="{StaticResource {x:Type igPrim:RowSelectorHeaderCellControl}}" TargetType="{x:Type igPrim:RowSelectorHeaderCellControl}"> <Setter Property="Background" Value="Silver"/> </Style>
But, How MyNewGridStyle knows to use MyNewHeaderCellStyle and MyNewHRowSelectorHeaderCellStyle and not the ones their based on?
Did i misunderstand something?
The thing you should do is to define the new Styles without Keys in the Resources of the XamGrid that you want to use them. I created a sample project for you showing this approach. The top XamGrid uses the default Style which has only a FontWeight set, while the bottom one use the new Style that has Opacity and is based on the one with the FontWeight. Please let me know if this is the functionality you want to achieve or I have misunderstood you.
Thanks Stefan.
I understood the idea of basedOn. but I can't see how it's helping me to solve the issue of using different "inner styles"..
i think i don't understand some basic things in the XamlGrid Style, so i'll be very glad if you will help me and send me complete example of the following situation:
- There are two grids in the xaml (exactly as you sent me now).
- The first is using style called "style1", and the second is using "style2".
- "style1" is the default Infragistics XamGrid style (that uses the default Infragistics XamGrid's "HeaderCellControl" style, and also the default "RowSelectorHeaderCellControl" and the default "CellControl" styles).
- "style2" is different from "style1" in the way that it's using different styles for it's HeaderCellControl, RowSelectorHeaderCellControl, CellControl (they should act as you told me in your first answer).
I'm sure THAT will answer all my questions :)
THANKS
If you change the Styles in the sample, I sent you, to target HeaderCellControl, you will see that the first XamGrid's Headers will be bold and the second one's will be Bold and with Opacity. If you want the second XamGrid to use only the new Style (has Opacity only) you can remove the BasedOn Property. Please let me know if you need further assistance on this matter.
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.