问题描述
我有一个自定义都市窗口,它充当启动屏幕。这是在其他线程中启动的。但是,调用Show()函数后,执行不会发生。我的意思是窗口没有显示。
protected async override void OnStartup(StartupEventArgs e)
{
string g = null;
var t = JsonConvert.SerializeObject(g);
bool creatednew;
Mutex mutex = new Mutex(true,"WpfApp1",out creatednew);
if (!creatednew)
{
MessageBox.Show("Not allowed");
this.Shutdown();
}
else
{
Window1 testwindow = null;
var m1 = new ManualResetEvent(false);
var t1 = new Thread(() =>
{
testwindow = new Window1();
testwindow.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/PresentationFramework.Aero,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml",UriKind.RelativeOrAbsolute) });
testwindow.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,/MahApps.Metro;component/Styles/Controls.xaml") });
testwindow.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,/MahApps.Metro;component/Styles/Fonts.xaml") });
testwindow.SetResourceReference(MetroWindow.BorderBrushProperty,"AccentColorBrush");
testwindow.Show();
m1.Set();
// When the window closes,shut down the dispatcher
testwindow.Closed += (s,k) =>
{
dispatcher.Currentdispatcher.BeginInvokeShutdown(dispatcherPriority.Background);
};
// Start the dispatcher Processing
dispatcher.Run();
});
t1.SetApartmentState(ApartmentState.STA);
t1.IsBackground = true;
t1.Start();
m1.WaitOne();
Current.MainWindow = new MainWindow();
Current.MainWindow.ShowDialog();
base.OnStartup(e);
}
}
如果我使用wpf窗口,则一切正常。最糟糕的是,如果我使用1.5.6.0版本,而没有将资源分配给tempWindow并在app.xaml中定义资源,则相同的代码将起作用。
<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" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)