2010-06-08 19 views
2

我为singleInstance应用程序创建了一些逻辑,我必须使用我自己的入口点(而不是App.xaml)作为Application。我在App.xaml中有一些样式现在不起作用。如何在我的情况下使用我的App.xaml中的这个ResourceDictionaries来完成整个项目?如何使用App.Xaml的ResourseDictionaries和自己的入口点

我的类管理应用程序启动

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。为什么?

回答

2

我找到了解决这个问题的办法。我创造新的资源字典中并粘贴到这个新字典我的所有其他地质矿产:

<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(); 
    } 
} 

我希望这个解决方案的帮助))

+0

如果您希望IDE在编辑器中使用此处定义的样式,则可以在App.xaml中添加对主资源字典的引用。但是,应用程序仍然会使用代码隐藏进行分配 – sridawg 2015-11-17 19:48:09

相关问题