c# - 如何使用具有自己入口点的 App.Xaml 的 ResourceDictionaries

标签 c# wpf app.xaml

我为 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/

相关文章:

c# - 如何在asp.net mvc中展平通过JsonResult返回的ExpandoObject?

c# - 在位图上绘制长字符串会导致绘制问题

c# - 为什么不在 finally block 中关闭数据库连接

c# - Winforms/WPF 互操作 - 调整嵌套用户控件的大小

wpf - 如何为 WPF 中的单选按钮绑定(bind) Checked 事件?

c# - Azure 上有多个应用程序 - 每个服务一个应用程序还是一体式应用程序?

c# - 使用 MVVM 时,在代码中的什么位置以及如何告诉文本框显示临时加载消息?

mahapps.metro - Mahapps metro 主题不可用,因为没有 app.xaml

wpf - 为什么窗口背景的样式设置不起作用?

wpf - 如何跨 WPF 应用程序定义公共(public)资源(包括模板)?