I need to style a subset of columns returned by a stored procedure that are dynamic i.e. certain column names will always be returned and have the same name and certain columns will vary based on what parameters were passed to the stored procedure. The style I want to apply is the width as well as change the font size and make the column read only or editable.
<igWPF:XamDataGrid.FieldLayouts> <igWPF:FieldLayout> <igWPF:FieldLayout.Fields>
<!-- THESE ARE STATIC COLUMNS -->
<igWPF:Field Name="valvegroup_log_ID" Visibility="Collapsed" /> <igWPF:Field Name="timeseq" Visibility="Collapsed" /> <igWPF:Field Name="cst" Visibility="Collapsed" /> <igWPF:Field Name="std_datetimeseq" Visibility="Collapsed" />
<igWPF:Field Name="Time" Label="Time" Width="50" />
<!-- HOW DO I APPLY A STYLE TO A SUBSET OF COLUMN WHOS QUANTITY AND NAME WILL VARY BASED ON PARAMETERS
PASSED TO STORED PROC? -->
</igWPF:FieldLayout.Fields> </igWPF:FieldLayout> </igWPF:XamDataGrid.FieldLayouts>
Thanks
Hi Kris,
Thank you for your post. I have been looking into your requirement and the easiest way to achieve it is applying CellValuePresenter style using data triggers. Because the fact that the data triggers do not provide any ‘OR’ statement you will need to declare data trigger for each of the possible fields like e.g.:
<Style TargetType="igDP:CellValuePresenter">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Field.Name}" Value="valvegroup_log_ID">
<Setter Property="Width" Value="200" />
<Setter Property="FontSize" Value="20"/>
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Field.Name}" Value="timeseq">
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Field.Name}" Value="cst">
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Field.Name}" Value="std_datetimeseq">
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Field.Name}" Value="Time">
</Style.Triggers>
</Style>
Let me know, if you need any further assistance on this matter.
Hello. Thanks for looking into this for me. I just need some more clarification. In your example all the data triggers have the Value property set to a column name. For some of the columns I will know the name like Time or std_datetimeseq like in your example above but for a subset of columns I will not know the name because those columns are dynamically generated by the stored proc based on parameters passed. I want to apply the same style to those columns. Would I do something like below where I leave the Value property out of the DataTrigger tag?
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Field.Name}" >
Thank you for your reply. I am glad that you have managed to resolve your issue.
Actually I just figured it out.
In order to use Brushes.AliceBlue you need
using System.Windows.Media;
but I had
using Brushes = System.Drawing.Brushes;
when I commented using Brushes = System.Drawing.Brushes; out and just used using System.Windows.Media; it worked.
Well I'm not sure what to say. I can't reproduce the exception in your test project even when I setup the layout exactly like my project.
Hi,
Thank you for your reply. I was looking into your new issue and I was not able to reproduce any exception on my side using the provided code snippet.
I am attaching a sample application(DataGridFieldBrush.zip) that I used for my test.
Could you please try to reproduce your issue with my sample application?
Looking forward to hearing from you.
Thanks for pointing me in the right way. I decided to use OnFieldLayoutInitialized instead of OnFieldLayoutInitializing. I also have another question. I would like to set the background cell color for certain columns with the below code:
var cellValuePresenterStyle = new Style(typeof(CellValuePresenter)); var backgroundSetter = new Setter(BackgroundProperty, Brushes.AliceBlue); cellValuePresenterStyle.Setters.Add(backgroundSetter);
someField.Settings.CellValuePresenterStyle = cellValuePresenterStyle
but I'm getting the following exception:
System.Drawing.SolidBrush' is not a valid value for the 'System.Windows.Controls.Panel.Background' property on a Setter.
Any idea why?