मेरे पास एक wpf एप्लिकेशन है और मैंने एक लॉगऑन विंडो बनाई है जिसका उपयोग एप्लिकेशन की कनेक्शन स्ट्रिंग बनाने के लिए किया जाता है। मुझे पहले संवाद को बंद करने में समस्याएं आ रही हैं और कताई इसके पीछे मेनविंडो खोलती है। मुझे लगता है कि एक करीबी घटना लॉगऑन संवाद से बाहर हो रही है और मेनविंडो में फंस रही है क्योंकि जैसे ही मैं कोडविंड में मेनविंडो ऑब्जेक्ट बनाता हूं और कॉल शो() को कॉल करता हूं, यह सिर्फ मेरे स्टार्टअप इवेंट हैंडलर से पहले और मेरे कन्स्ट्रक्टर में चला जाता है मेनविंडो के हैंडलर को कभी भी विंडो को दिखाए बिना। App.xaml में ShutdownMode = "OnMainWindowClose" निर्दिष्ट है।wpf- application_Startup - लोड संवाद विंडो THEN mainwindow
private void Application_Startup(object sender, StartupEventArgs e)
{
try
{
Chooser thechooser = new Chooser();
thechooser.ShowDialog();
}
catch (Exception ex)
{
}
//initialize datalayer
dataLayer = new Mxxx41.DAL(this.CurrentConnectionString);
MainWindow appmainwindow = new MainWindow();
Application.Current.MainWindow = appmainwindow;
appmainwindow.Activate();
appmainwindow.Show();
}
private void LogInButton_Click(object sender, RoutedEventArgs e)
{
//get ip from listbox selection
XmlElement currentelement = (XmlElement)Listbox.SelectedItem;
string ip = ((string)currentelement.Attributes["IP"].Value);
string instancename = string.Empty;
if (!((string)currentelement.Attributes["InstanceName"].Value == string.Empty))
{
instancename = ((string)currentelement.Attributes["InstanceName"].Value);
}
//ping that IP
Boolean pingresult = ping.PingHost(ip);
Boolean sqlresult = false;
if (pingresult)
{
if (!(String.IsNullOrEmpty("instancename")))
{
ip = string.Format("{0}\\{1}", ip, instancename);
}
//build connection string with that IP
string connstr = BuildConnStr(ip);
//create datalayer
Mxxx41.DAL datalayer = new Mxxx41.DAL(connstr);
//validate credentials
DataSet data = datalayer.getDataSet("login_checkcredentials", CommandType.StoredProcedure, datalayer.CreateParameter("@username", SqlDbType.VarChar, this.UsernameTextbox.Text), datalayer.CreateParameter("@password", SqlDbType.VarChar, this.PasswordTextbox.Text));
if (data.Tables[0].Rows.Count > 0)
{
sqlresult = true;
//log in user
//build new user code omitted for brevity
App myAppReference = ((App)Application.Current);
myAppReference.CurrentUser = thisuser;
myAppReference.CurrentConnectionString = connstr;
//close window
this.Close(); //this is the close event I think is causing issues.
}
}
else
{
ErrorLabel.Content = string.Format("{0}{1}", "could not ping selected Host :", ip);
}
//return true
}
public MainWindow(){
this.InitializeComponent();
this.SideBarExpander.IsExpanded = true;
this.Loaded += onLoaded;
this.Closed += onClosed;
this.Closing += onClosing;
try
{
//this.DataLayer = ((Mxxx41.DAL)MyDemoApp.App.Current.Properties["DataLayer"]);
App myAppReference = ((App)Application.Current);
this.DataLayer = myAppReference.GetDataLayer();
}
catch //catch everything for the moment
{
this.DataBaseConnectionError = true;
}
ExceptionList = new List<Error>();
}
क्या कोई इस व्यवहार से मेरी मदद कर सकता है?
धन्यवाद जैच। यह सही था। मुझे समझ में नहीं आया कि मेरी संवाद विंडो ने मेनविंडो संदर्भ को चुरा लिया है, भले ही मैं मेनविंडो ऑब्जेक्ट को नीचे कुछ पंक्तियों को रीसेट करता हूं। – TWood
@TWood: आपका स्वागत है। मुझे लगता है कि भ्रमित चीज शायद यह है कि 'ऑनमाइन विन्डोक्लोस' का मतलब यह नहीं है कि 'मेनविंडो' विंडो बंद हो जाती है, लेकिन जब पहली विंडो खुलती है। –