Hi folks,
I've been trying to fine tune the look and feel of a XamDataGrid by applying a gradient to the background and making the default cell background white rather than transparent, but of course, the custom style is ignored if you're using the Theme property to style the XamDataGrid.
I came across this blog entry by Andrew Smith which suggests using a style BasedOn the theme's style which would work nicely.
http://blogs.infragistics.com/blogs/andrew_smith/archive/2009/12/09/common-style-issues-when-using-the-theme-property.aspx
The trick is the BasedOn attribute requires the name/key of the theme style. Where do I find these names?
For example, in the last xaml snippet in the block the style is defined as:
<Style TargetType="igWindows:TabItemEx" BasedOn="{x:Static igThemes:PrimitivesOffice2k7Black.TabItemEx}"> <Setter Property="FontWeight" Value="Bold" /></Style>
How do I know to use "igThemes:PrimitivesOffice2k7Black.TabItemEx"? Where can I get these values?
CheersDavid
Hello David,
You can find all the styles/templates/brushes/resource keys in the defaul xaml files that we ship with the product. They are located in the DefaultStyles directory in the ProgramFiles\Infragistics folder.
Thanks Alex.
I was aware of the those files and had looked through them. It's probably lack of knowledge on my part but many of them don't have x:Keys they just have a TargetType. Take the style for the XamTextEditor in EditorsOffice2k7Blue_Express.xaml for example.
<Style TargetType="{x:Type igEditors:XamTextEditor}">...</Style>
How do I create another style BasedOn this style?
e.g. If I want to put a validation error message in the tooltip I'd do this for a standard TextBox..
<igEditors:XamTextEditor Text="{Binding Contact.Name, ValidatesOnDataErrors=True}" Theme="Office2k7Blue"> <igEditors:XamTextEditor.Resources> <Style TargetType="{x:Type igEditors:XamTextEditor}" BasedOn="WHAT_DO_I_PUT_HERE?"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="True"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource self}, Path=(Validation.Errors)[0].ErrorContent}"/> <Setter Property="Background" Value="#FFFFA5A5"/> </Trigger> </Style.Triggers> </Style> </igEditors:XamTextEditor.Resources> </igEditors:XamTextEditor>What do I use as the attribute value, and how do I determine this value from the style files you provide?CheersDavid
David,
The syntax is as follows:
BasedOn="{x:Static igThemes:GroupingNameThemeName.TargetElement}"
Grouping names can be : Primitives, Editors, DataPresenter.
ThemeNane is the name of the theme - Royale, Onyx,Office2k7Black,etc
TargetElement - name of the element that you want to create the style for
Example:
BasedOn="{x:Static igThemes:DataPresenterRoyale.LabelPresenter}".
Hi there,
I am having a very similar problem, the difference is I have a customized theme of my own say MyTheme. In one of the grids that I am using I need to override the CellValuePresenter style to do custom coloring. I need this style to be based on my custom theme. The question is how can I make the static style igThemes:DataPresenterMyTheme.CellValuePresenter available in the MyTheme implementation so that I can use it in "BasedOn: in other assemblies.
Thanks much
deyvi
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}"
<!—right here I need something like:
BasedOn="{x:Static igThemes:DataPresenterMyTheme.CellValuePresenter}" -->
>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},
Path=Field.Name}" Value="AField">
<Setter Property="Foreground"
Value="{Binding Path=DataItem.Aproperty, Converter={StaticResource doubleToBrushConverter}}" />
</DataTrigger>
</Style.Triggers>
</Style>
</igDP:XamDataGrid.Resources>
I try the following, but does not work.
<Window x:Class="DynamicTabControl.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igWindows="http://infragistics.com/Windows" xmlns:igDp="http://infragistics.com/DataPresenter" xmlns:igThemes="http://infragistics.com/Themes" Title="MainWindow" Height="450" Width="700"> <Grid> <igWindows:XamTabControl Name="xamTabCtrl" ItemsSource="{Binding Collection}" Theme="{x:Static igThemes:DataPresenterMetro.LabelPresenter}"> <igWindows:XamTabControl.ItemContainerStyle> <Style TargetType="{x:Type igWindows:TabItemEx} BasedOn="{igThemes:DataPresenterRoyale.LabelPresenter}"> <Setter Property="Header" Value="{Binding Path=Header}" /> </Style>
What do I wron?
Hello jean-Pascal,
Thank you for your post. I have been looking into it and I can say that if you want to set a theme to a WPF control you can set its Theme property. Also if you want to override a particular element’s Properties and use the theme as well you have to follow the steps in the blog from the first post. The BasedOn Property of the Style should be set to the same theme’s element as the Theme Property of the parent control. The Theme property is enum type and have predefined values. I created a sample project for you where I set the Metro theme to the XamTabControl and override the background of the TabItem, by putting the Style for it in the XamTabControl’s Resources. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.