How can I use application-scoped resources when my application builds as 'Page' and not 'Application Definition'?

Will

I want to use a custom Main method in my WPF application.

To do that, I need to build the application XAML file as a Page, instead of an application definition :

enter image description here

When I try to define a style as a resource :

<Application
    x:Class="MyProgram.Program"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyProgram"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <Style x:Key="WindowStyle" TargetType="{x:Type Window}">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                        <GradientStop Color="White" Offset="0" />
                        <GradientStop Color="Black" Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
    </Application.Resources>
</Application>

and I try to use that style in my window :

<Window
    x:Class="MyProgram.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:MyProgram"
    mc:Ignorable="d" Style="{StaticResource WindowStyle}"
    Title="MainWindow" Height="350" Width="525"/>

even though the designer works fine, when I try and run the program, it does not end well. I get an exception, the inner exception which reads {"Cannot find resource named 'WindowStyle'. Resource names are case sensitive."}

When the Build Action on the program is ApplicationDefinition, everything goes fine. But like I said, when I set it as Page ( which I need to for the sake of being able to define a custom main method ), I can't use the styles defined in the application resources.

Why is that? Is there a work-around?

Adam Smejkal

Put your Main() method into a custom class, and in Project Properties -> Application set Startup object to your custom class. Your new Main() method should get called upon startup and you don't have to build App.xaml as Page, which should solve the problems with resource resolution.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I use my Application Resources from another window?

From Dev

How can I add application resources to my C# backend for the application instead of in the XAML file?

From Dev

How can I use stackedit's markdown editor in my application

From Dev

How can I use svg images within my iOS application

From Dev

How can I use CSS styling in my GTK# application?

From Dev

How can I use the dictionary application in my language?

From Dev

How can I use the dictionary application in my language?

From Dev

How can I use jBPM in my GWT application?

From Dev

How can I use my own application bar with tilt effec?

From Dev

How can I use svg images within my iOS application

From Dev

How Can I Use Weather Icons on My Weather Application

From Dev

Can I use minimob advertise in my application?

From Dev

Can I use minimob advertise in my application?

From Dev

How can i start my application when network connection is available?

From Dev

How can I speed up maven builds of JavaFX application?

From Dev

How can I retrieve the injector for my application?

From Dev

how can i evaluate my spark application

From Dev

How can I keep my application in the foreground?

From Dev

Application scoped resources (JDBC) configured post deployment

From Dev

How can I use piwik in an ember application?

From Dev

How can I use jQuery in CatberryJS application?

From Dev

How I can use Buttons in a cordova application?

From Dev

I need an overview of Stormpath and can I use it in my web application?

From Dev

intellij java desktop application how to use resources

From Dev

How can I use an application class in order to start a service and use it in my activities?

From Dev

I get "Can't install application" error in XCode when trying to run my application on my iPhone for debug

From Dev

I get "Can't install application" error in XCode when trying to run my application on my iPhone for debug

From Dev

How can I get my ad banner to the bottom of my application?

From Dev

How can I decouple my application from my membership service?

Related Related

  1. 1

    How do I use my Application Resources from another window?

  2. 2

    How can I add application resources to my C# backend for the application instead of in the XAML file?

  3. 3

    How can I use stackedit's markdown editor in my application

  4. 4

    How can I use svg images within my iOS application

  5. 5

    How can I use CSS styling in my GTK# application?

  6. 6

    How can I use the dictionary application in my language?

  7. 7

    How can I use the dictionary application in my language?

  8. 8

    How can I use jBPM in my GWT application?

  9. 9

    How can I use my own application bar with tilt effec?

  10. 10

    How can I use svg images within my iOS application

  11. 11

    How Can I Use Weather Icons on My Weather Application

  12. 12

    Can I use minimob advertise in my application?

  13. 13

    Can I use minimob advertise in my application?

  14. 14

    How can i start my application when network connection is available?

  15. 15

    How can I speed up maven builds of JavaFX application?

  16. 16

    How can I retrieve the injector for my application?

  17. 17

    how can i evaluate my spark application

  18. 18

    How can I keep my application in the foreground?

  19. 19

    Application scoped resources (JDBC) configured post deployment

  20. 20

    How can I use piwik in an ember application?

  21. 21

    How can I use jQuery in CatberryJS application?

  22. 22

    How I can use Buttons in a cordova application?

  23. 23

    I need an overview of Stormpath and can I use it in my web application?

  24. 24

    intellij java desktop application how to use resources

  25. 25

    How can I use an application class in order to start a service and use it in my activities?

  26. 26

    I get "Can't install application" error in XCode when trying to run my application on my iPhone for debug

  27. 27

    I get "Can't install application" error in XCode when trying to run my application on my iPhone for debug

  28. 28

    How can I get my ad banner to the bottom of my application?

  29. 29

    How can I decouple my application from my membership service?

HotTag

Archive