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.
Hi Petar,
Thanks for your solution. We looked at other solutions involving adding Style Setters to XamTextEditor and CellValuePresenter, but SimpleTextBlock seems to be a better solution in terms of centralising the Style in a resource dictionary.
Thanks for your help!
Jason
Hello Jason,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
If the above suggestion helped you solve your issue please verify the thread as answered so other users may take better advantage of it.
I have modified your sample so it uses a style like yours (Grid_simpleTextBlock.zip), however the XamEditors do not have a TextBlock inside them, to which you can apply this resource. I suppose you can use your resource if you retemplate the XamDataGrid’s cells or editors so they can incorporate it.
Please let me know if you require any further clarification on the matter.
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,
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.