Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1540
Applying a keyed TextBlock resource to multiple UnboundField
posted

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.

Sandbox.zip
Parents
No Data
Reply
  • 27093
    posted

    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" />

        </Style>

    </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" />

    </Style>

     

    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 TargetType="{x:Type igED:XamDateTimeEditor}" >

        <Style.Resources>

            <Style BasedOn="{StaticResource myTextBlockStyle}" TargetType="{x:Type igWindows:SimpleTextBlock}" >

            </Style>

        </Style.Resources>

        <Setter Property="Mask" Value="hh:mm:ss" />

    </Style>

     

    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.

Children