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 7970271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:22:19+00:00 2026-06-04T07:22:19+00:00

I can’t understand why happens this. I have a simple application in WPF. This

  • 0

I can’t understand why happens this. I have a simple application in WPF. This application have a window, and in the App.xaml have defined one style, that changes the style of all the buttons:

<Application x:Class="PruebasDesk.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="Window1.xaml">
    <Application.Resources>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Height" Value="23"></Setter>
            <Setter Property="Width" Value="75"></Setter>
            <Setter Property="Background" Value="DarkCyan"></Setter>
        </Style>
    </Application.Resources>
</Application>

This works fine, all the buttons get the style. Now, here is the problem. If instead of using the StartupUri attribute to start the application, I start it with using the OnStartup method:

public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            Window1 win1 = new Window1();
            win1.Show();
        }
    }

The buttons of the application don’t get applied the button style defined at App.xaml. But… if I add another style to the App.xaml, like this:

<Application x:Class="PruebasDesk.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             >
    <Application.Resources>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Height" Value="23"></Setter>
            <Setter Property="Width" Value="75"></Setter>
            <Setter Property="Background" Value="DarkCyan"></Setter>
        </Style>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Height" Value="23"></Setter>
            <Setter Property="Width" Value="180"></Setter>
            <Setter Property="Background" Value="Azure"></Setter>
        </Style>
    </Application.Resources>
</Application>

Then the buttons get the style applied!!! This seems really weird to me. Does anyone know if I am missing something?

  • 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-04T07:22:20+00:00Added an answer on June 4, 2026 at 7:22 am

    I can’t tell you with certainty why that behavior occurs but I can tell you that best practices would have steered you away from using App.xaml in that fashion. What I believe to be a better practice is to only merge in your resource dictionaries in app.xaml. Storing the actual styles is a good way to create an unmanageable project.

    Create a new ResourceDictionary file and add those styles. Merge the dictionaries in as you add more of them.

      <Application.Resources>
        <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Common.xaml"/>
          </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
      </Application.Resources>
    

    Alternatively, you could hook into the event Startup (app.xaml: Startup="App_Startup") and not override OnStartup. This will work with the App.xaml resource setup you have defined. It is likely a timing issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can any one tell me clearly why ? Reading is simple in ArrayList,( we
Can functors be defined locally within the body of a function? One possible use
Can you have submenus with the top level set to checkable in WPF? I
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can I order my users in the database, so I don't have to say
Can any one tell, how to get the result of LINQ query contains group
Can anyone explain to me why this program: for(float i = -1; i <
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and

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.