2016-08-09 129 views
-3

Ich habe einige Formulare in meiner WPF-Anwendung. Ich habe mein Startformular in App.xaml angegeben, sagen wir es Form A. IrgendwieWPF-Feuerungsereignisse, die beim Start von Formularen nicht vorhanden sind

, wenn die Anwendung gestartet wird, Brennen meine anderen Formen Veranstaltungen wie

  • Combobox Auswahl
  • geändert
  • Checkbox
  • geändert checked

Ich bin nur Form A und don öffnen möchten Ich möchte keine anderen Formen, die feuern. Gibt es eine einfache Möglichkeit zu verhindern, dass diese Ereignisse ausgelöst werden?

Ok das ist mein app.xaml

<Application x:Class="MMS.UI.App" 
 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 
      xmlns:sys="clr-namespace:System;assembly=mscorlib" 
 
      xmlns:local="clr-namespace:MMS.UI" 
 
      StartupUri="FormAcilis.xaml"> 
 
    <!--<Application.Resources> 
 
     <ResourceDictionary> 
 
      <ResourceDictionary.MergedDictionaries> 
 
       <ResourceDictionary Source="Themes/Metro/Metro.MSControls.Core.Implicit.xaml" /> 
 
       <ResourceDictionary Source="Themes/Metro/Metro.MSControls.Toolkit.Implicit.xaml" /> 
 
      </ResourceDictionary.MergedDictionaries> 
 
     </ResourceDictionary> 
 
    </Application.Resources>--> 
 
    <Application.Resources> 
 
     <ResourceDictionary> 
 
      <ResourceDictionary.MergedDictionaries> 
 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 
 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" /> 
 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> 
 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 
 
       <ResourceDictionary Source="/Resources/Icons.xaml" /> 
 
      </ResourceDictionary.MergedDictionaries> 
 
      <local:NullToBooleanConverter x:Key="ntb"/> 
 
      <local:NullToVisibilityConverter x:Key="ntv"/> 
 
      <local:NullToBooleanRevConverter x:Key="ntbr"/> 
 
      <BooleanToVisibilityConverter x:Key="btv" /> 
 
      <local:BooleanToVisibilityRevConverter x:Key="btvr"/> 
 
      <local:GroupsToTotalConverter x:Key="gtt"/> 
 
      <local:GroupsToTotalConverter2 x:Key="gtt2"/> 
 
      <local:DurumToBooleanConverter x:Key="dtb"/> 
 
      <local:DurumToBooleanConverterRev x:Key="dtbr"/> 
 
      <local:DosyalarToPathConverter x:Key="dtp"/> 
 
      <Style x:Key="RightAligned" TargetType="TextBlock"> 
 
       <Setter Property="HorizontalAlignment" Value="Right"/> 
 
      </Style> 
 
     </ResourceDictionary> 
 
    </Application.Resources> 
 
</Application>

Und das ist die App.xaml.cs

namespace MMS.UI 
 
{ 
 
    /// <summary> 
 
    /// Interaction logic for App.xaml 
 
    /// </summary> 
 
    public partial class App : Application 
 
    { 
 
     public App() 
 
     { 
 
      base.DispatcherUnhandledException += App_DispatcherUnhandledException; 
 
     } 
 

 
     void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) 
 
     { 
 
      var ex = new CustomException(e.Exception, "Providers, App.xaml()"); 
 
     } 
 

 
     protected override void OnStartup(StartupEventArgs e) 
 
     { 
 
      Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("tr-TR"); ; 
 
      Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("tr-TR"); ; 
 

 
      FrameworkElement.LanguageProperty.OverrideMetadata(
 
       typeof(FrameworkElement), 
 
       new FrameworkPropertyMetadata(
 
        XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); 
 

 
      base.OnStartup(e); 
 
     } 
 
    } 
 
}

Ich bin nicht versuchen zu öffnen o andere Formen. Aber ihre Ereignisse schießen immer noch.

+1

Wenn Ereignisse aus anderen Fenstern ausgelöst werden, öffnen Sie andere Fenster. Tu das einfach nicht. –

+6

Sie erstellen offensichtlich die anderen Formulare, bevor sie angezeigt werden, sie initialisieren und die Ereignisse werden ausgelöst. Niemand kann Ihnen sagen, wo in Ihrem Code das passiert, ohne Ihren Code zu sehen. –

+0

Danke für Kommentare. Ich habe meine Frage bearbeitet und den Code eingefügt. –

Antwort

0

Ok dachte ich mir schlecht und das war, weil eine Funktion, die die anderen Formen wie folgt initialisieren:

List<MetroWindow> wndList = new List<MetroWindow>(); 
 
      try 
 
      { 
 
       Assembly uiProject = Assembly.Load("MMS"); 
 
       foreach (Type t in uiProject.GetTypes()) 
 
       { 
 
        if (t.BaseType == typeof(MetroWindow)) 
 
        { 
 
         var emptyCtor = t.GetConstructor(Type.EmptyTypes); 
 
         if (emptyCtor != null) 
 
         { 
 
          MetroWindow f = (MetroWindow)emptyCtor.Invoke(new object[] { }); 
 
          // t.FullName will help distinguish the unwanted entries and 
 
          // possibly later ignore them 
 
          wndList.Add(f); 
 
         } 
 
        } 
 
       } 
 
       return wndList; 
 
      } 
 
      catch (Exception err) 
 
      { 
 
       // log exception 
 
       return null; 
 
      }

Ich habe versucht haben, welche Fenster mein Projekt zu bekommen. Entschuldige mein schlechtes Englisch. Ihr empfiehlt mir für die Lösung angezündet.