Using application resources in add-ins

Operations Dashboard for ArcGIS defines a number of style, font, and brush resources that are used throughout the application. These same resources can also be re-used by widgets, map tools, map toolbars, and feature actions in add-ins. By re-using application resources, add-ins can easily achieve appearance and behaviour that is consistent with the existing application.

Additionally, application resources will adapt automatically to changes in the application settings for theme (light, medium or dark) and text size (small, medium or large).

To see examples of application resources being used, see the samples provided in the ArcGIS Runtime SDK for WPF Sample Browser.

For a list of application resources, see Application resource reference.

Implicit styles

The application will also apply some implicit styling to certain types of control, in addition to the explict styles that can be applied using application resources, as described below.

  • ListBoxItem
  • ListViewItem
  • ComboBox
  • ComboBoxItem
  • TextBlock
  • TextBox
  • TreeViewItem

If a custom add-in user interface includes the use of these types of control, some elements of styling will automatically be applied to the controls without requiring any resource declarations. Any explicit styling used on these types of controls will superceed any styling applied implicitly; for example, TextBlocks would require styles in order to style the text as a particular type of text such as a heading or sub-heading.

How To: Use application resources in Xaml

  1. Open the Xaml for the widget, map toolbar, map tool or dialog that will use application resources.
  2. In the root element declaration, add a namespace declaration to the ESRI.ArcGIS.OperationsDashboard namespace, in the assembly of the same name:

    Namespace declaration for ESRI.ArcGIS.OperationsDashboard namespace

    xmlns:opsCenter="clr-namespace:ESRI.ArcGIS.OperationsDashboard;assembly=ESRI.ArcGIS.OperationsDashboard"
    
  3. Use the required application resource to set the value of the property within the Xaml. For a full list of application resources and the controls or properties they can be used for, see see Application resource reference.

    For example, the code section below shows how the ThemedButtonStyle could be used to set the Style property of a Button in a custom widget.

    Using the ThemedButtonStyle resource to set the Style of a Button.

    <Button Style="{StaticResource ThemedButtonStyle}" Click="Button_Click">Click Me</Button>
    

    The code section below shows how the ThemedMediumTextBlockStyle could be used to set the Style of a TextBlock used as a heading in custom widget, and how the ThemedForegroundBrush can also be used to set the color of the text in the TextBlock.

    Using the ThemedMediumTextBlockStyle and ThemedForegroundBrush to set the Style and Brush of a TextBlock in a widget.

    <TextBlock Text="Widget Heading Text" Style="{StaticResource ThemedMediumTextBlockStyle}" 
          Foreground="{DynamicResource ThemedForegroundBrush}" />
    

Advice on applying resources

Styles can be referenced using static resources; the brushes and text sizes that the styles reference are themselves dynamic, which allows the brushes and text sizes used by the application styles to change in response to the user changing theme or text size settings in the application. Declaring the resources to be static is more efficient than declaring them to be ynamic.

If using brush or text size resources to set Brush or FontSize properties, declare the resource to be dynamic, in order to allow the property to respond to changes in theme or text size setting.

1/27/2015