Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9087211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:39:26+00:00 2026-06-16T21:39:26+00:00

When we define a Style in an XAML resource section & set it’s TargetType

  • 0

When we define a Style in an XAML resource section & set it’s TargetType property to a specific control type then we do not need to set Style property to control of that type. e.g.

<Window.Resources>
        <Style TargetType="Button">
            <Setter Property="Content" Value="Style set for all buttons"/>
            <Setter Property="Background" Value="Gray"/>
        </Style>
    </Window.Resources>
    <Grid>
        <Button Height="27" HorizontalAlignment="Left" Margin="119,56,0,0" Name="button1" VerticalAlignment="Top" Width="140" />
        <Button Style="{x:Null}" Content="No Style" Height="27" HorizontalAlignment="Left" Margin="212,121,0,0" Name="button2" VerticalAlignment="Top" Width="141" />
        <Button  Content="Button" Height="25" HorizontalAlignment="Left" Margin="296,183,0,0" Name="button3" VerticalAlignment="Top" Width="158" />
    </Grid>

But when we want to define a style for all controls in a window then we need to add Style property to each control to have that defined style. e.g.

<Window.Resources>
        <Style x:Key="Style1" TargetType="Control">
            <Setter Property="Control.Background" Value="Gray"/>
        </Style>
    </Window.Resources>
    <Grid>
        <Button Style="{StaticResource Style1}" Content="Button" Height="23" HorizontalAlignment="Left" Margin="67,52,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
        <Label Style="{StaticResource Style1}" Content="Label" Height="27" HorizontalAlignment="Left" Margin="189,99,0,0" Name="label1" VerticalAlignment="Top" Width="83" />
    </Grid>

Can’t we access style “Style1” with Button & Label in above example without setting Style property specifically in Button & Label controls?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:39:27+00:00Added an answer on June 16, 2026 at 9:39 pm

    Similar question as to here

    General consensus is that you cannot apply a style to something as esoteric as just the control. Considering the wide range of properties and controls, I can understand why the system rejects/ignores it. I would suggest maybe something like this to get you fairly close to what you would want:

    <Style x:Key="general" TargetType="{x:Type Control}">
            <Setter Property="Control.Background" Value="Green"/>
    </Style>
    <Style BasedOn="{StaticResource general}" TargetType="{x:Type Button}"/>
    <Style BasedOn="{StaticResource general}" TargetType="{x:Type Label}"/>
    <Style BasedOn="{StaticResource general}" TargetType="{x:Type CheckBox}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set the style of the root Control element in my XAML
I am using style to define the template of a predefined control. The control
Why is there no list-style infinite type error when I define something like this
I want to define control styles in a resource dictionary and use those for
I Have a ResourceDictionary Generic.xaml which consists of a set of other resource dictionaries,
I'm trying to define a common Width resource in Common.xaml which will be shared
I defined resource in XAML for SystemColors. It is working great if I set
I am trying to define a control template that I then want to use
I have the following Style (defined as a Resource in xaml). This is basically
I am trying to set a style for my user control. The UserControl is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.