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

  • Home
  • SEARCH
  • 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 3394798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:12:47+00:00 2026-05-18T04:12:47+00:00

I want to create a style which I can apply to different control types.

  • 0

I want to create a style which I can apply to different control types. Something like this:

<ToolBar>
    <ToolBar.Resources>
        <Style TargetType="Control">
            <Setter Property="Margin" Value="1"/>
            <Setter Property="Padding" Value="0"/>
        </Style>
    </ToolBar.Resources>

    <ComboBox .../>
    <Button .../>
</ToolBar>

And it should apply to the ComboBox and the Button. But it doesn’t work like I’ve written it here.

Is this possible somehow? To target only an ancestor of these classes, like Control? If not, what would be the best way to apply common settings to a bunch of control?

  • 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-05-18T04:12:48+00:00Added an answer on May 18, 2026 at 4:12 am

    Update

    See this discussion for an interesting approach

    See this question

    The Style you are creating is only targeting Control and not elements that derive from Control. When you don’t set the x:Key you implicitly set the x:Key to TargetType, so if TargetType=”Control”, then x:Key=”Control”. I don’t think there’s any direct way to accomplish this.

    Your options are

    <Style x:Key="ControlBaseStyle" TargetType="Control">  
        <Setter Property="Margin" Value="1"/>  
        <Setter Property="Padding" Value="0"/>  
    </Style>  
    

    Target all Buttons and ComboBoxes for instance

    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource ControlBaseStyle}"/> 
    <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource ControlBaseStyle}"/> 
    

    or use the the style directly on the Control

    <Button Style="{StaticResource ControlBaseStyle}" ...>
    <ComboBox Style="{StaticResource ControlBaseStyle}" ...>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I create parametrized control template, i.e. create control template which might contain different
I want to create a custom style for an activity that will look like
I want to create a user control [textbox] which convert all the text in
I want to create a navigation bar similar to this site's: http://www.mysupermarket.co.uk/#/shelves/top_offers_in_asda.html Can anyone
in my silverlight application i want to create a style from code behind and
Hi i want to create a generic style for pin button. <Window x:Class=TooglePinButtonStyle.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
I'm using the new RichTextBox control in SL4Beta and want to create styles for
I want create wordpress website into which I want create user management... That means
I want create an application with animate button? how can i do? after click
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =

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.