I found an example in the documentation on how to change the column headers style. It suggests creating a style with LabelPresenter as the target type and ommitting a key so that it is applied to all column headers. I need to change the style on just a few headers. Is there a way I can assign a header style per column?
Thanks for your help,
Mike
You can set the LabelPresenterStyle on a FieldSettings instance. The FieldSettings class is exposed from the Field (via its Settings property), on the FieldLayout (via its FieldSettings property) and on the control (via its FieldSettings property).
<igDP:XamDataGrid >
<igDP:XamDataGrid.Resources>
<Style x:Key="italicLabel" TargetType="{x:Type igDP:LabelPresenter}">
<Setter Property="FontStyle" Value="Italic" />
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:Field Name="MyFieldName">
<igDP:Field.Settings>
<igDP:FieldSettings LabelPresenterStyle="{StaticResource italicLabel}" />
</igDP:Field.Settings>
</igDP:Field>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Many thanks, that's percisely what I was looking for.
But for some reason I cannot get multiple FieldLayout to show up -- on the first one shows up. In the example below, only MyFieldName1 shows up (MyFieldName2 & 3 are missing). Any ideas why that might happen?
<igDP:Field Name="MyFieldName1"/>
<igDP:Field Name="MyFieldName2"/>
<igDP:Field Name="MyFieldName3"/>
Your defining each field in a different field layout. A record is only associated with a single fieldlayout so if your underlying data has all 3 fields then you should define the fields in a single fieldlayout.
Thanks for your help Andrew, that clears it up.
One more problem I'm having, if you wouldn't mind helping. I'm using the "Onyx" theme which creates very attractive headers with small rectangles around the header label (as well as a slight blue glow affect on mouse-over). When I set a field to use my LabelPresenterStyle, and the only thing in the style is to change the foreground, I lose the rectangle around the label, I lose the mouse-over effect, the bottom of the header changes (there's a control-color line across the bottom), and the vertical alignment of the header text shifts. Is there a way I can override the LabelPresenterStyle but still preserve most of the nice visuals provided by the theme?
Since the Style resolution in WPF is such that once it finds a Style, it will only fallback to the style in the defining assembly (the default style), I think you will need to set the BasedOn of the Style to that style in the onyx theme.
e.g.
<Style TargetType="{x:Type igDP:LabelPresenter}" BasedOn="{StaticResource {x:Static igThemes:DataPresenterOnyx.LabelPresenter}}">
Note, if you change the theme property or put a different theme resourcedictionary into the resources then you will need to change the based on accordingly.
You da man! That did the trick. Thanks!
Sorry the snippet I provided had a mistake. You just need to remove the StaticResource since that property will return the style.
<Style TargetType="{x:Type igDP:LabelPresenter}"
BasedOn="{x:Static igThemes:DataPresenterOnyx.LabelPresenter}">
That makes sense, thanks Andrew. I'm having trouble getting this to work however. In your sample you set the BasedOn as DataPresenterOnyx.LabelPresenter. Is LabelPresenter the name of the Style and the Type? My understanding is BasedOn has to refer to a Style. I think this might be why it is not working for me. What is the name of the LabelPresenter Style in the Onyx theme?
Thanks again,
Mike.