Hi,
I'm new to the xamDataGrid, so I might have missed something here. I'm using Infragistics for WPF 2011.1.
My application uses the Office2010Blue theme by default. For grids, this theme does not have vertical gridlines between the cells. If I centre-justify a column, however, a vertical gridline will appear next to the column. I've attached an image to this post that illustrates the issue-see the rating column, right hand grid line; the effect is very subtle, but noticable.
I've replicated the issue in the xamFeatureBrowser with the following code changes to .\xamFeatureBrowser\Samples\XamDataGrid\SimpleStyles_Samp.xaml
<igDP:Field Name="qbrate" Label="Rating"> <igDP:Field.Settings> <!--igDP:FieldSettings EditAsType="{x:Type sys:Double}" /--> <igDP:FieldSettings> <igDP:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="HorizontalContentAlignment" Value="Center" /> </Style> </igDP:FieldSettings.CellValuePresenterStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Is this an intended consequence of centre alignment? Is there anyway to override/fix this behaviour? Preferably at an application level as I have many grids that are affected by this issue.
Thanks in advance,
Rik
I talk about this issue (scenario 2 of problem #1) in my blog post. Basically there is only 1 local style in WPF so if you are setting a Style property then the Style provided by the Theme will not be used. You need to set the BasedOn for your Style. E.g. BasedOn="{x:Static igThemes:DataPresenterOffice2010Blue.CellValuePresenter}"
This looks like exactly the sort of thing I'm after, thanks!
When I tried applying it to my application I discovered that the theme is being applied at runtime via code using:
ThemeManager.CurrentTheme = this.RetrieveDefaultTheme();
Given that I don't know what theme is active at design time, what do I need to put in the based on attribute? Is there a way to get the currently applicable style from the theme manager?
Thanks for the help with this,
That is going to be a problem. Unfortunately there is no support in WPF for having a "dynamic" basedon.
As to the question of getting style information from the ThemeManager, no the ThemeManager has no notion of where the ResourceDictionaries it is providing are coming from in terms of classes like (DataPresenterOffice2010Blue) if that is what you are asking. If you did need that you would likely need to use reflection to enumerate the types defined in the DataPresenter assembly. e.g.
var s = GetDataPresenterThemeStyle( ThemeManager.ThemeNameOffice2010Blue, "CellValuePresenter" ); } private static Style GetDataPresenterThemeStyle(string theme, string styleProperty) { var t = typeof( DataPresenterResourceSet<> ); foreach ( var type in typeof( DataPresenterBase ).Assembly.GetExportedTypes() ) { var baseType = type.BaseType; if ( baseType != null && baseType.IsGenericType && baseType.GetGenericTypeDefinition() == t ) { var locator = baseType.GetProperty( "Location" ).GetValue( null, Type.EmptyTypes ) as ResourceSetLocator; if ( locator.Theme == theme ) { return baseType.GetProperty( styleProperty ).GetValue( null, Type.EmptyTypes ) as Style; } } } return null; }
var s = GetDataPresenterThemeStyle( ThemeManager.ThemeNameOffice2010Blue, "CellValuePresenter" ); }
private static Style GetDataPresenterThemeStyle(string theme, string styleProperty) { var t = typeof( DataPresenterResourceSet<> ); foreach ( var type in typeof( DataPresenterBase ).Assembly.GetExportedTypes() ) { var baseType = type.BaseType;
if ( baseType != null && baseType.IsGenericType && baseType.GetGenericTypeDefinition() == t ) { var locator = baseType.GetProperty( "Location" ).GetValue( null, Type.EmptyTypes ) as ResourceSetLocator;
if ( locator.Theme == theme ) { return baseType.GetProperty( styleProperty ).GetValue( null, Type.EmptyTypes ) as Style; } } }
return null; }
Thanks for your reply. I've botched up a solution based on your help. thanks!
Here's the code, it needs some refinement, but it works in principal. I've added a call to SetStyle after InitializeComponent in the constructor. This is based on the SimpleStyles_Samp.xaml.cs file. Note: this code probably reveals my ignorance of WPF/Xaml, so I can quite imagine there are getter ways to achieve this :-)
private void SetStyle () { var style = GetDataPresenterThemeStyle(Infragistics.Windows.Themes.ThemeManager.CurrentTheme, "CellValuePresenter"); Style newStyle = new Style(typeof(CellValuePresenter), style); newStyle.Setters.Add(new Setter(CellValuePresenter.HorizontalAlignmentProperty, HorizontalAlignment.Center)); var layout = this.XamDataGrid1.FieldLayouts.FirstOrDefault(); var field = layout.Fields.FirstOrDefault(f => f.Name == "qbrate"); field.Settings.CellValuePresenterStyle = newStyle; } private static Style GetDataPresenterThemeStyle (string theme, string styleProperty)
{
// Code provided in previous reply by Andrew Smith
}