我为 singleInstance 应用程序创建了一些逻辑,我必须为应用程序使用我自己的入口点(不是 App.xaml)。我在 App.xaml 中有一些样式现在不起作用。在我的情况下,如何将 App.xaml 中的 ResourceDictionaries 用于整个项目?
我的管理应用程序启动的类
public class SingleInstanceManager : WindowsFormsApplicationBase
{
App app;
public SingleInstanceManager()
{
this.IsSingleInstance = true;
}
protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
try
{
// First time app is launched
app = new App();
App.Current.Properties["rcID"] = e.CommandLine;
//IntroLibrary.OpenDocumentFromNotify();
app.Run();
return false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
{
// Subsequent launches
base.OnStartupNextInstance(eventArgs);
Intro win = (Intro)app.MainWindow;
if (eventArgs != null)
{
App.Current.Properties["rcID"] = eventArgs.CommandLine[0];
}
IntroLibrary.OpenDocumentFromNotify();
app.Activate();
}
}
和我自己的切入点:
public class EntryPoint
{
[STAThread]
public static void Main(string[] args)
{
SingleInstanceManager manager = new SingleInstanceManager();
manager.Run(args);
}
}
还有我的 App.Xaml 代码:
public partial class App : Application
{
protected override void OnStartup(System.Windows.StartupEventArgs e)
{
base.OnStartup(e);
// Create and show the application's main window
Intro window = new Intro();
window.Show();
}
public void Activate()
{
// Reactivate application's main window
this.MainWindow.Activate();
}
}
我的 App.xaml 有一些代码描述了不起作用的 ResourceDictionaries。为什么?
最佳答案
我找到了这个问题的解决方案。我创建了新的资源词典并将我所有其他资源粘贴到这个新词典中:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="themes/ShinyBlue.xaml" />
<ResourceDictionary Source="themes/Anim.xaml" />
<ResourceDictionary Source="themes/Generic.xaml" />
<ResourceDictionary Source="themes/CustomStyles.xaml" />
<ResourceDictionary Source="themes/Resource.xaml" />
<ResourceDictionary Source="themes/CustomWindowChrome.xaml" />
</ResourceDictionary.MergedDictionaries>
然后稍微编辑了我的 App.cs
public partial class App : Application
{
protected override void OnStartup(System.Windows.StartupEventArgs e)
{
base.OnStartup(e);
ResourceDictionary rd = new ResourceDictionary() { Source = new Uri("CommonStyle.xaml",UriKind.RelativeOrAbsolute) };
this.Resources = rd;
// Create and show the application's main window
Intro window = new Intro();
window.Show();
}
public void Activate()
{
// Reactivate application's main window
this.MainWindow.Activate();
}
}
我希望这个解决方案对某人有所帮助 )))
关于c# - 如何使用具有自己入口点的 App.Xaml 的 ResourceDictionaries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2997748/