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

How can I speed up maven builds of JavaFX application?

How can I use Facebook JAVA API in my application?

how can i version a java application between builds?

How can I embed Maven into my application?

How can I use the application twice as dependency

How can I correctly run a timed process in my app the will start on stop when the application is in use or in the background?

How can I use Firebase Admin SDK in my Angular application?

How can I embed NetLimiter in my application

How can I make my application logout when the browser is closed?

Can I use llvm in my commercial application?

Can I store my application data in kubernetes configuration resources?

How i can use Poppler-QML-plugin in my application?

How can I log from my python application to splunk, if I use celery as my task scheduler?

How can I use Google Fonts in my PySimpleGUI desktop application?

How can i use the database sqlite in my application?

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

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

How can I use the dictionary application in my language?

Can I use minimob advertise in my application?

How can I use jBPM in my GWT application?

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

How can I use svg images within my iOS application

Application scoped resources (JDBC) configured post deployment

How can I keep my application in the foreground?

How I can use Buttons in a cordova application?

How Can I Use Weather Icons on My Weather Application

How can I use a link on my website to open an application?

how can i use broadcast receiver in my application

How can I use same, single class loader for every WAR application packaged in my EAR application?