Using a Base TargetType

Although the Style in Figure 18.1 is shared among three Buttons, it can be shared by any kind of Control if you mark it with TargetType="Control" instead:

<Page ...>...        <Style x:Key="PurpleTiltStyle" TargetType="Control" >...      <Button Style="{StaticResource PurpleTiltStyle}" Content="1"/>      <ToggleSwitch Style="{StaticResource PurpleTiltStyle}"/>      <ProgressRing IsActive="True" Style="{StaticResource PurpleTiltStyle}"/>...</Page>

The result is shown in Figure 18.2. Note that ToggleSwitch’s default appearance enforces a minimum width, so it ignores the Style’s Width setting.

FIGURE 18.2 Heterogeneous controls given the same Style

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.