[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Collapse]Common Concepts
  [Expand]Themes
  [Expand]Images
  [Expand]Printing and Exporting
  [Expand]Saving and Restoring Layouts
   Typed Styles
  [Expand]Touch Support
  [Expand]Expressions
  [Expand]Formatting Values
   Prism Adapters
  [Expand]Data Sources
   XAML Namespaces
 [Expand]MVVM Framework
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Typed Styles

The typed style allows you to define element style in a simplified manner.

Starting with v.17.2, the DevExpress WPF subscription provides the DevExpress.Xpf.TypedStyles assembly that contains typed styles for the following controls:

  • for controls from base WPF assemblies (WindowsBase, PresentationCore, PresentationFramework);
  • DevExpress WPF controls.

This topic consists of the following sections:

Expanded Typed Styles vs. Regular Styles

The image below demonstrates the difference between the regular style and typed style.

To set a regular style for multiple buttons, you should implement a Style with TargetType=Button and specify each property in a separate Setter.

The typed styles allow you to define a style for all the buttons in the following way:

  • Create a new resource with a name like {ElementName}Style, where {ElementName} is a target type.

    Example: ButtonStyle for the standard Button control, GridControlStyle for the DevExpress GridControl.

  • Define the property values directly without setters. Define the typed style's x:Name property.
  • Assign the typed style to control the same way you assign regular styles.

Expanded Supported features

Typed styles support all the regular style features.

Attached properties

Attached properties are collected in MergedStyles property:

Events

You can specify event handlers without EventSetters:

Markup Extensions

Markup extensions that return their value immediately (all except BindingBase and DynamicResoureExtension) can be used in typed styles in a regular way:

Use the "*_Source" properties for the BindingBase and DynamicResourceExtension markup extensions:

DevExpress Extensions (DXBinding/DXEvent/DXCommand)

DXBinding/DXCommand work seamlessly with typed styles.

Note

DXEvent does not work with typed styles.

Base styles

You can define base styles in the following manner:

Setters

You can use regular setters by populating the *Style.Setters collection.

Implicit styles

To define implicit styles, use x:Key instead of TargetType:

The target type is set to typed style internally, so you should not set it manually. For example, to define the VirtualizingPanelStyle for ListBox, you need to define the ListBoxStyle first.

Triggers

In addition to typed styles, the DevExpress.Xpf.TypedStyles assembly contains typed triggers for each supported control:

You can use typed triggers in templates. To do this, specify the typed trigger's SourceName or TemplateName property:

If you create triggers for multiple source objects, you can define multiple triggers:

Data triggers

Use TypedDataTrigger to use typed styles with data triggers.

Expanded Using in your code

References and namespaces

All the typed styles and triggers are implemented in the {Corresponding control namespace}.TypedStyles namespaces.

Example: ButtonStyle - System.Windows.Controls.TypedStyles.

The typed styles' XAML namespaces are the same as the corresponding controls' namespaces, so you do not need to add any additional namespace references. To use the typed styles, you need reference the DevExpress.Xpf.TypedStyles assembly in your project.

 

Limitation

Visual Studio and Blend do not support typed styles. We recommend using typed styles when you edit XAML manually.

Performance

Typed styles have comparable performance to regular styles.

The following regular styles are applied for 200 ms on a testing machine:

The following analog implemented via typed styles is applied for 130 ms on a testing machine:

Is this topic helpful?​​​​​​​