Is it possible to set the startup form to be a static string value?
As we know we can specify which view to start up by setting the property StartupUri
as the below code.
<Application x:Class="SomeClass"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
>
</开发者_如何学GoApplication>
My question: Can we put in a static string value for the view name, ie. MainWindow.xaml
?
I tried below code but it doesn't work. Please share if you know how to. Thank you!
<Application x:Class="Demo.WPFSkill.App"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyPublicStaticClassNamespace"
StartupUri="{x:Static Member=local:MyPublicStaticClass.AStaticValue}"
>
</Application>
Edit My purpose: To put in the right name to start the application in such a way that NOT rely on a string value.
Thanks to mzabsky
, I think I better code it in the code behind as below code.
public partial class App : Application
{
public App()
{
var mainWindow = new MainWindow();
mainWindow.Show();
}
}
Hope this is helpful!
You can remove the StartupUri parameter from XAML and open the window manually from the App class from C# code.
EDIT:
Example (assuming the static value is a type name of the main window class):
public partial class App : Application
{
public App()
{
Window window = (Window) Activator.CreateInstance(Assembly.GetExecutingAssembly.GetType(MyPublicStaticClass.AStaticValue));
window.Show();
}
}
精彩评论