2010-06-08 4 views
2

J'ai créé une logique pour l'application singleInstance et je dois utiliser mon propre point d'entrée (pas App.xaml) pour Application. J'ai quelques styles dans App.xaml qui ne fonctionne pas maintenant. Comment puis-je utiliser ce ResourceDictionaries de mon App.xaml pour l'ensemble du projet dans ma situation?Comment utiliser ResourseDictionaries de App.Xaml avec son propre point d'entrée

Ma classe pour gérer l'application de démarrage

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

et mon propre point d'entrée:

public class EntryPoint 
{ 
    [STAThread] 
    public static void Main(string[] args) 
    { 
     SingleInstanceManager manager = new SingleInstanceManager(); 
     manager.Run(args); 
    } 
} 

Et mon code app.xaml derrière:

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

Et mon App.xaml a un code qui décrit ResourceDictionaries qui ne fonctionne pas. Pourquoi?

Répondre

2

J'ai trouvé une solution à ce problème. Je crée une nouvelle ressource de dictionnaire et de coller tous mes autres Resourse dans ce nouveau dictionnaire:

<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> 

puis vient de modifier un peu mes 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(); 
    } 
} 

J'espère que cette aide de la solution Quelqu'un)))

+0

Si vous souhaitez que l'EDI utilise les styles définis ici dans l'éditeur, vous pouvez ajouter une référence au dictionnaire de ressources principal dans App.xaml. Cependant, l'application fera toujours l'affectation en utilisant le code-behind – sridawg

Questions connexes