Reputation: 4611
I am a newbie to WPF.I have a problem in developing the WPF application where I want to start a class as start up object,after I want to Show the welcome form. When I was trying to put the main method in that class set the project properties startup object as that class. I am getting this error "The calling thread must be STA, because many UI components require this.".
How can we resolve this error by making the main method of that class as startup object?
Upvotes: 1
Views: 3512
Reputation: 1035
in top App.xaml
Exit="App_Exit"
Startup="App_Startup"
in app.xaml.cs
void App_Startup(object sender, StartupEventArgs e)
private void App_Exit(object sender, ExitEventArgs e)
There other events you can subscribe to, if you are really needing to override App as startup you need define in your Program.cs like this:
public static class Program
{
[STAThread]
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Main(string[] args)
{
And somewhere in there
App app = new App();
app.InitializeComponent();
app.Run();
Upvotes: 3
Reputation: 4215
When you say "welcome form" do you mean Window
?
Have you tried setting the StartupUri of the App.xaml?
<Application x:Class="DemoApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="WelcomeWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Upvotes: -1