启动表单上不存在WPF触发事件

时间:2016-08-09 13:42:26

标签: c# wpf forms events

我的WPF应用程序中有一些表单。我在App.xaml中指定了我的启动表单,让我们说表单A

当应用程序启动时,我的其他形式'像

这样的事件
  • 组合框选择已更改
  • 复选框已更改

我只想打开表单A ,并且不希望其他表单事件触发。有没有简单的方法来防止这些事件被解雇?

好的,这是我的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>
&#13;
&#13;
&#13;

这是app.xaml.cs

&#13;
&#13;
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);
        }
    }
}
&#13;
&#13;
&#13;

我没有试图打开任何其他形式。但他们的事件仍然在解决。

1 个答案:

答案 0 :(得分:0)

好的,我认为我的不好,那是因为一个初始化其他形式的函数:

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

我试图让我的项目有哪些窗口。抱歉英文不好。你的赞扬点亮了我的解决方案。