Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird behavior with styles in XAML
    primarykey
    data
    text
    <p>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:</p> <pre><code>&lt;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"&gt; &lt;Application.Resources&gt; &lt;Style TargetType="{x:Type Button}"&gt; &lt;Setter Property="Height" Value="23"&gt;&lt;/Setter&gt; &lt;Setter Property="Width" Value="75"&gt;&lt;/Setter&gt; &lt;Setter Property="Background" Value="DarkCyan"&gt;&lt;/Setter&gt; &lt;/Style&gt; &lt;/Application.Resources&gt; &lt;/Application&gt; </code></pre> <p>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:</p> <pre><code>public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { Window1 win1 = new Window1(); win1.Show(); } } </code></pre> <p>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:</p> <pre><code>&lt;Application x:Class="PruebasDesk.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" &gt; &lt;Application.Resources&gt; &lt;Style TargetType="{x:Type Button}"&gt; &lt;Setter Property="Height" Value="23"&gt;&lt;/Setter&gt; &lt;Setter Property="Width" Value="75"&gt;&lt;/Setter&gt; &lt;Setter Property="Background" Value="DarkCyan"&gt;&lt;/Setter&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="Height" Value="23"&gt;&lt;/Setter&gt; &lt;Setter Property="Width" Value="180"&gt;&lt;/Setter&gt; &lt;Setter Property="Background" Value="Azure"&gt;&lt;/Setter&gt; &lt;/Style&gt; &lt;/Application.Resources&gt; &lt;/Application&gt; </code></pre> <p>Then the buttons get the style applied!!! This seems really weird to me. Does anyone know if I am missing something?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload