启动窗体上不存在WPF触发事件
本文关键字:事件 WPF 不存在 窗体 启动 | 更新日期: 2023-09-27 18:01:24
我的WPF应用程序中有一些表单。我在app。xaml中指定了启动表单假设它是 form 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>
这是app。example。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);
}
}
}
我没有尝试打开任何其他表单。但是他们的事件还在触发
好吧,我知道我错了,这是因为一个函数初始化其他形式像这样:
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;
}
我想知道我的项目有哪些窗口。抱歉我的英语不好。你的建议对我有帮助。