检查加载程序集中的 window 是否打开
Check if window from loaded assembly is open
我有下面的代码,在单击按钮时执行,从另一个 application.exe
打开 window
gAssembly = Assembly.LoadFrom(JLDBConnection.Properties.Settings.Default.DefaultString + @"\JLRetailTerminal.exe");
Type typ = gAssembly.GetExportedTypes().Where(s => s.Name == "RetailWindow").FirstOrDefault();
typ.GetMethod("Show").Invoke(Activator.CreateInstance(typ), null);
gAssembly
是一个全局变量。
如何检查 "RetailWindow" 是否已打开并且不打开另一个 window?
你是唯一一个创造者吗?如果是这样,您可以存储 window 实例并检查 IsVisible:
即:
g_wnd = (Window)Activator.CreateInstance(type);
if (!g_wnd.IsVisible)
{
}
完整解决方案。
var gAssembly = Assembly.LoadFrom(JLDBConnection.Properties.Settings.Default.DefaultString + @"\JLRetailTerminal.exe");
Type typ = gAssembly.GetExportedTypes().Where(s => s.Name == "RetailWindow").FirstOrDefault();
//if extend sale is set prevent multiple windows
if (gWindow == null)
{//show if window has never been opened
gWindow = (Window)Activator.CreateInstance(typ);
gWindow.Show();
}
else
{//window has been opened
var windows = Application.Current.Windows; //get all opened windows in applications
if (!windows.OfType<Window>().Contains(gWindow) || !(JLDBConnection.Properties.Settings.Default.ExtendSale == "Yes"))
{ //if window has been closed or not multiple sale database
gWindow = (Window)Activator.CreateInstance(typ);
gWindow.Show();
}
}
我有下面的代码,在单击按钮时执行,从另一个 application.exe
打开 windowgAssembly = Assembly.LoadFrom(JLDBConnection.Properties.Settings.Default.DefaultString + @"\JLRetailTerminal.exe");
Type typ = gAssembly.GetExportedTypes().Where(s => s.Name == "RetailWindow").FirstOrDefault();
typ.GetMethod("Show").Invoke(Activator.CreateInstance(typ), null);
gAssembly
是一个全局变量。
如何检查 "RetailWindow" 是否已打开并且不打开另一个 window?
你是唯一一个创造者吗?如果是这样,您可以存储 window 实例并检查 IsVisible:
即:
g_wnd = (Window)Activator.CreateInstance(type);
if (!g_wnd.IsVisible)
{
}
完整解决方案。
var gAssembly = Assembly.LoadFrom(JLDBConnection.Properties.Settings.Default.DefaultString + @"\JLRetailTerminal.exe");
Type typ = gAssembly.GetExportedTypes().Where(s => s.Name == "RetailWindow").FirstOrDefault();
//if extend sale is set prevent multiple windows
if (gWindow == null)
{//show if window has never been opened
gWindow = (Window)Activator.CreateInstance(typ);
gWindow.Show();
}
else
{//window has been opened
var windows = Application.Current.Windows; //get all opened windows in applications
if (!windows.OfType<Window>().Contains(gWindow) || !(JLDBConnection.Properties.Settings.Default.ExtendSale == "Yes"))
{ //if window has been closed or not multiple sale database
gWindow = (Window)Activator.CreateInstance(typ);
gWindow.Show();
}
}