I have a XamDataGrid bound to data that consists of a DateTime field and some string fields using UnboundField elements in the XAML. The DateTime field specifies EditAsType as DateTime so that I can modify the XamDateTimeEditor.Mask property in the EditorStyle.
However, I have a keyed resource with a TargetType of TextBlock that I wish to apply to all of my fields. I know that the underlying control for XamDateTimeEditor and the auto-generated XamTextEditor controls for my string fields is a TextBlock.
The mocked-up XAML and C# code for this situation is in the attachment. How do I apply the keyed resource to all of the fields without messing up the XamDateTimeEditor and without repeating XAML code for each UnboundField? Also, my restrictions are: the resource cannot change; and the fields must remain UnboundFields.
Thanks.
Hello Jason,
I have been researching this issue for you and even though there is no such supported functionality I have managed to find the source of all you troubles. Actually there seems to be a few “sources”. First of all if you have a DateTime value the XamDataGrid automatically uses a XamDateTimeEditor and if you use a string type value the auto-generated XamTextEditor controls are XamTextEditors. Inside the XamTextEditor the XamTextEditor’s ControlTemplate there used to be a TextBlock for the non-edit mode, however since 10.3, in the XamTextEditors’ template for non-edit mode, instead of a TextBlock, a SimpleTextBlock is used. The situation is the same for all other XamEditors (XamDateTimeEditor, XamNumericEditor, XamCurrencyEditor, etc.). Another obstacle in front of you would be the absence of a property that you could use to set your keyed resource.
In order to reference a SimpleTextBlock style to your inside your XamEditor’s style you can use the Style’s Resources like so:
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igED:XamDateTimeEditor}" >
<Style.Resources>
<Style TargetType="{x:Type igWindows:SimpleTextBlock}" >
<Setter Property="Foreground" Value="Aqua" />
</Style>
</Style.Resources>
<Setter Property="Mask" Value="hh:mm:ss" />
</igDP:FieldSettings.EditorStyle>
Hover from reading through your description I assume that all the editors with one resource that would look something like:
<Style x:Key="myTextBlockStyle" TargetType="{x:Type igWindows:SimpleTextBlock}">
<Setter Property="Foreground" Value="Red" />
I have also though of a way for you to use this with a property from the XamEditors. E.g. if you want to add this to the DateTime UnboundField you can modify your style to:
<Style BasedOn="{StaticResource myTextBlockStyle}" TargetType="{x:Type igWindows:SimpleTextBlock}" >
That way every styled Field that has this reference will have a non-edit mode text as defined in your myTextBlockStyle style.
Please let me know if you require any further clarification on the matter or if I have misunderstood you in any way.
Thanks for your reply.
I have tried what you suggested, but as I mentioned in my original post, I am under a restriction that my myTextBlockStyle resource cannot change. However, I have tried adding the following to my resources (in StackPanel.Resources) in the example project I attached, but it is having no effect:
<Style TargetType="{x:Type igWindows:SimpleTextBlock}" BasedOn="{StaticResource myTextBlockStyle}" />
Please note, as I mentioned in my original post, I wish this style to be applied to all of my fields in the grid, not just the DateTime field.
Thanks,
Jason