How to know Last Window-Startup-Location When it was just closed ? WPF Application [duplicate].NET WPF Remember window size between sessionsWPF image resourcesHow to set default WPF Window Style in app.xaml?How to set WPF window's startup ClientSize?WPF Application that only has a tray iconHow do I exit a WPF application programmatically?How do I make a WPF window movable by dragging the extended window frame?Setting design time DataContext on a Window is giving a compiler error?How to customize startup of WPF application?How to make the text length of the title of a WPF Window greater 255 characters?Centering a WPF Page on a screen when starting a WPF application

Can I apply for a working holiday visa at age 30 and get the full 12 months?

Densest sphere packing

What is the most suitable position for a bishop here?

How to best clean this sealed rotary encoder / volume knob?

Is declining an undergraduate award which causes me discomfort appropriate?

Predict the product from the reaction

How much steel armor can you wear and still be able to swim?

Unable to import binding 'SforceServiceBinding' with the Summer 19 Tooling API WSDL

What is the "ls" directory in my home directory?

Boundaries and Buddhism

Are there any individual aliens that have gained superpowers in the Marvel universe?

Time at 1 g acceleration to travel 100 000 light years

Print 'A' 1000 times with BrainFuck

Summing cube roots in fractions

Why do you need to heat the pan before heating the olive oil?

Are intrusions within a foreign embassy considered an act of war?

Story of a Witch Boy

Umlaut character order when sorting

How can a warlock learn from a spellbook?

Synaptic Static - when to roll the d6?

「捨ててしまう」why is there two て’s used here?

Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?

Why there is a red color in right side?

Justifying Affordable Bespoke Spaceships



How to know Last Window-Startup-Location When it was just closed ? WPF Application [duplicate]


.NET WPF Remember window size between sessionsWPF image resourcesHow to set default WPF Window Style in app.xaml?How to set WPF window's startup ClientSize?WPF Application that only has a tray iconHow do I exit a WPF application programmatically?How do I make a WPF window movable by dragging the extended window frame?Setting design time DataContext on a Window is giving a compiler error?How to customize startup of WPF application?How to make the text length of the title of a WPF Window greater 255 characters?Centering a WPF Page on a screen when starting a WPF application






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0
















This question already has an answer here:



  • .NET WPF Remember window size between sessions

    14 answers



I'm Working on a WPF application which automatically restart after specific interval of time (I'm using DispatcherTimer for that purpose). The problem is how to know WPF window's last Startup_Location.. Because I needed to set that location when it restart..



(I have set Default Startup_Location "CenterOwner" in XAML code like



WindowStartupLocation="CenterOwner"


but if user change that location then I need to know that location to set when WPF restart)



Secondly How to know WPF window was minimized last time as this is also need to set when it restart
Thanks










share|improve this question















marked as duplicate by Hans Passant .net
Users with the  .net badge can single-handedly close .net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 25 at 8:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 3





    You can save the required info in an xml file before window closes, and read the info from xml before loading the window again.

    – Mathivanan KP
    Mar 25 at 7:01











  • Thanks for reply @MathivananKP .. How to save that info in xmal and apply when it reload ? I'm new in WPF..

    – Bilal Tahir
    Mar 25 at 7:05






  • 1





    You can save the state in userconfig file. Here is how.

    – Mathivanan KP
    Mar 25 at 7:11

















0
















This question already has an answer here:



  • .NET WPF Remember window size between sessions

    14 answers



I'm Working on a WPF application which automatically restart after specific interval of time (I'm using DispatcherTimer for that purpose). The problem is how to know WPF window's last Startup_Location.. Because I needed to set that location when it restart..



(I have set Default Startup_Location "CenterOwner" in XAML code like



WindowStartupLocation="CenterOwner"


but if user change that location then I need to know that location to set when WPF restart)



Secondly How to know WPF window was minimized last time as this is also need to set when it restart
Thanks










share|improve this question















marked as duplicate by Hans Passant .net
Users with the  .net badge can single-handedly close .net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 25 at 8:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 3





    You can save the required info in an xml file before window closes, and read the info from xml before loading the window again.

    – Mathivanan KP
    Mar 25 at 7:01











  • Thanks for reply @MathivananKP .. How to save that info in xmal and apply when it reload ? I'm new in WPF..

    – Bilal Tahir
    Mar 25 at 7:05






  • 1





    You can save the state in userconfig file. Here is how.

    – Mathivanan KP
    Mar 25 at 7:11













0












0








0









This question already has an answer here:



  • .NET WPF Remember window size between sessions

    14 answers



I'm Working on a WPF application which automatically restart after specific interval of time (I'm using DispatcherTimer for that purpose). The problem is how to know WPF window's last Startup_Location.. Because I needed to set that location when it restart..



(I have set Default Startup_Location "CenterOwner" in XAML code like



WindowStartupLocation="CenterOwner"


but if user change that location then I need to know that location to set when WPF restart)



Secondly How to know WPF window was minimized last time as this is also need to set when it restart
Thanks










share|improve this question

















This question already has an answer here:



  • .NET WPF Remember window size between sessions

    14 answers



I'm Working on a WPF application which automatically restart after specific interval of time (I'm using DispatcherTimer for that purpose). The problem is how to know WPF window's last Startup_Location.. Because I needed to set that location when it restart..



(I have set Default Startup_Location "CenterOwner" in XAML code like



WindowStartupLocation="CenterOwner"


but if user change that location then I need to know that location to set when WPF restart)



Secondly How to know WPF window was minimized last time as this is also need to set when it restart
Thanks





This question already has an answer here:



  • .NET WPF Remember window size between sessions

    14 answers







c# .net wpf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 15:51







Bilal Tahir

















asked Mar 25 at 6:06









Bilal TahirBilal Tahir

3418




3418




marked as duplicate by Hans Passant .net
Users with the  .net badge can single-handedly close .net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 25 at 8:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Hans Passant .net
Users with the  .net badge can single-handedly close .net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 25 at 8:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 3





    You can save the required info in an xml file before window closes, and read the info from xml before loading the window again.

    – Mathivanan KP
    Mar 25 at 7:01











  • Thanks for reply @MathivananKP .. How to save that info in xmal and apply when it reload ? I'm new in WPF..

    – Bilal Tahir
    Mar 25 at 7:05






  • 1





    You can save the state in userconfig file. Here is how.

    – Mathivanan KP
    Mar 25 at 7:11












  • 3





    You can save the required info in an xml file before window closes, and read the info from xml before loading the window again.

    – Mathivanan KP
    Mar 25 at 7:01











  • Thanks for reply @MathivananKP .. How to save that info in xmal and apply when it reload ? I'm new in WPF..

    – Bilal Tahir
    Mar 25 at 7:05






  • 1





    You can save the state in userconfig file. Here is how.

    – Mathivanan KP
    Mar 25 at 7:11







3




3





You can save the required info in an xml file before window closes, and read the info from xml before loading the window again.

– Mathivanan KP
Mar 25 at 7:01





You can save the required info in an xml file before window closes, and read the info from xml before loading the window again.

– Mathivanan KP
Mar 25 at 7:01













Thanks for reply @MathivananKP .. How to save that info in xmal and apply when it reload ? I'm new in WPF..

– Bilal Tahir
Mar 25 at 7:05





Thanks for reply @MathivananKP .. How to save that info in xmal and apply when it reload ? I'm new in WPF..

– Bilal Tahir
Mar 25 at 7:05




1




1





You can save the state in userconfig file. Here is how.

– Mathivanan KP
Mar 25 at 7:11





You can save the state in userconfig file. Here is how.

– Mathivanan KP
Mar 25 at 7:11












1 Answer
1






active

oldest

votes


















1














As others have already pointed out, you will have to store the attributes of the window to persist them between the starts. In order to set the location of the Window you have to set WindowStartupLocation to WindowStartupLocation.Manual. You would have to start the main window manually from the App.xaml.cs.



In order to change the way WPF starts your application, you have to modify the App.xaml and change the active property StartupUri to the event handler property Startup and assign a handler method to it (in this case named Run):



<Application x:Class="WpfTestRange.Main.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Run">
</Application>


Then implement the handler in the App.xaml.cs and start the main window manually:



private void Run(object sender, StartupEventArgs e)

this.MainWindow = new MainWindow();
this.MainWindow.Closing += SaveWindowAttributes;
RestoreWindow();
this.MainWindow.Show();


protected void RestoreWindow()

this.MainWindow.WindowStartupLocation = WindowStartupLocation.Manual;
var reader = new AppSettingsReader();

string windowStateValue;
try

windowStateValue = reader.GetValue("WindowState", typeof(string)) as string;

catch (InvalidOperationException)

// There are no previously persisted values (first launch)
return;


WindowState windowState;
if (!string.IsNullOrWhiteSpace(windowStateValue) && Enum.TryParse(windowStateValue, out windowState))

this.MainWindow.WindowState = windowState;


string windowTopValue = reader.GetValue("WindowPositionTop", typeof(string)) as string;
string windowLeftValue = reader.GetValue("WindowPositionLeft", typeof(string)) as string;

double windowPositionTop;
double windowPositionLeft;
if (!string.IsNullOrWhiteSpace(windowStateValue)
&& double.TryParse(windowTopValue, out windowPositionTop)
&& double.TryParse(windowLeftValue, out windowPositionLeft))

this.MainWindow.Top = windowPositionTop;
this.MainWindow.Left = windowPositionLeft;




private void SaveWindowAttributes(object sender, CancelEventArgs e)

string sectionName = "appSettings";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

string currentWindowState = this.MainWindow.WindowState.ToString();
if (config.AppSettings.Settings["WindowState"] == null)

config.AppSettings.Settings.Add("WindowState", currentWindowState);

else

config.AppSettings.Settings["WindowState"].Value = currentWindowState;


string currentWindowPositionTop = this.MainWindow.Top.ToString("G");
if (config.AppSettings.Settings["WindowPositionTop"] == null)

config.AppSettings.Settings.Add("WindowPositionTop", currentWindowPositionTop);

else

config.AppSettings.Settings["WindowPositionTop"].Value = currentWindowPositionTop;


string currentWindowPositionLeft = this.MainWindow.Left.ToString("G");
if (config.AppSettings.Settings["WindowPositionLeft"] == null)

config.AppSettings.Settings.Add("WindowPositionLeft", currentWindowPositionLeft);

else

config.AppSettings.Settings["WindowPositionLeft"].Value = currentWindowPositionLeft;

config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sectionName);






share|improve this answer

























  • @BilalTahir I edited the answer to show this step.

    – BionicCode
    Mar 26 at 7:46

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














As others have already pointed out, you will have to store the attributes of the window to persist them between the starts. In order to set the location of the Window you have to set WindowStartupLocation to WindowStartupLocation.Manual. You would have to start the main window manually from the App.xaml.cs.



In order to change the way WPF starts your application, you have to modify the App.xaml and change the active property StartupUri to the event handler property Startup and assign a handler method to it (in this case named Run):



<Application x:Class="WpfTestRange.Main.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Run">
</Application>


Then implement the handler in the App.xaml.cs and start the main window manually:



private void Run(object sender, StartupEventArgs e)

this.MainWindow = new MainWindow();
this.MainWindow.Closing += SaveWindowAttributes;
RestoreWindow();
this.MainWindow.Show();


protected void RestoreWindow()

this.MainWindow.WindowStartupLocation = WindowStartupLocation.Manual;
var reader = new AppSettingsReader();

string windowStateValue;
try

windowStateValue = reader.GetValue("WindowState", typeof(string)) as string;

catch (InvalidOperationException)

// There are no previously persisted values (first launch)
return;


WindowState windowState;
if (!string.IsNullOrWhiteSpace(windowStateValue) && Enum.TryParse(windowStateValue, out windowState))

this.MainWindow.WindowState = windowState;


string windowTopValue = reader.GetValue("WindowPositionTop", typeof(string)) as string;
string windowLeftValue = reader.GetValue("WindowPositionLeft", typeof(string)) as string;

double windowPositionTop;
double windowPositionLeft;
if (!string.IsNullOrWhiteSpace(windowStateValue)
&& double.TryParse(windowTopValue, out windowPositionTop)
&& double.TryParse(windowLeftValue, out windowPositionLeft))

this.MainWindow.Top = windowPositionTop;
this.MainWindow.Left = windowPositionLeft;




private void SaveWindowAttributes(object sender, CancelEventArgs e)

string sectionName = "appSettings";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

string currentWindowState = this.MainWindow.WindowState.ToString();
if (config.AppSettings.Settings["WindowState"] == null)

config.AppSettings.Settings.Add("WindowState", currentWindowState);

else

config.AppSettings.Settings["WindowState"].Value = currentWindowState;


string currentWindowPositionTop = this.MainWindow.Top.ToString("G");
if (config.AppSettings.Settings["WindowPositionTop"] == null)

config.AppSettings.Settings.Add("WindowPositionTop", currentWindowPositionTop);

else

config.AppSettings.Settings["WindowPositionTop"].Value = currentWindowPositionTop;


string currentWindowPositionLeft = this.MainWindow.Left.ToString("G");
if (config.AppSettings.Settings["WindowPositionLeft"] == null)

config.AppSettings.Settings.Add("WindowPositionLeft", currentWindowPositionLeft);

else

config.AppSettings.Settings["WindowPositionLeft"].Value = currentWindowPositionLeft;

config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sectionName);






share|improve this answer

























  • @BilalTahir I edited the answer to show this step.

    – BionicCode
    Mar 26 at 7:46















1














As others have already pointed out, you will have to store the attributes of the window to persist them between the starts. In order to set the location of the Window you have to set WindowStartupLocation to WindowStartupLocation.Manual. You would have to start the main window manually from the App.xaml.cs.



In order to change the way WPF starts your application, you have to modify the App.xaml and change the active property StartupUri to the event handler property Startup and assign a handler method to it (in this case named Run):



<Application x:Class="WpfTestRange.Main.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Run">
</Application>


Then implement the handler in the App.xaml.cs and start the main window manually:



private void Run(object sender, StartupEventArgs e)

this.MainWindow = new MainWindow();
this.MainWindow.Closing += SaveWindowAttributes;
RestoreWindow();
this.MainWindow.Show();


protected void RestoreWindow()

this.MainWindow.WindowStartupLocation = WindowStartupLocation.Manual;
var reader = new AppSettingsReader();

string windowStateValue;
try

windowStateValue = reader.GetValue("WindowState", typeof(string)) as string;

catch (InvalidOperationException)

// There are no previously persisted values (first launch)
return;


WindowState windowState;
if (!string.IsNullOrWhiteSpace(windowStateValue) && Enum.TryParse(windowStateValue, out windowState))

this.MainWindow.WindowState = windowState;


string windowTopValue = reader.GetValue("WindowPositionTop", typeof(string)) as string;
string windowLeftValue = reader.GetValue("WindowPositionLeft", typeof(string)) as string;

double windowPositionTop;
double windowPositionLeft;
if (!string.IsNullOrWhiteSpace(windowStateValue)
&& double.TryParse(windowTopValue, out windowPositionTop)
&& double.TryParse(windowLeftValue, out windowPositionLeft))

this.MainWindow.Top = windowPositionTop;
this.MainWindow.Left = windowPositionLeft;




private void SaveWindowAttributes(object sender, CancelEventArgs e)

string sectionName = "appSettings";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

string currentWindowState = this.MainWindow.WindowState.ToString();
if (config.AppSettings.Settings["WindowState"] == null)

config.AppSettings.Settings.Add("WindowState", currentWindowState);

else

config.AppSettings.Settings["WindowState"].Value = currentWindowState;


string currentWindowPositionTop = this.MainWindow.Top.ToString("G");
if (config.AppSettings.Settings["WindowPositionTop"] == null)

config.AppSettings.Settings.Add("WindowPositionTop", currentWindowPositionTop);

else

config.AppSettings.Settings["WindowPositionTop"].Value = currentWindowPositionTop;


string currentWindowPositionLeft = this.MainWindow.Left.ToString("G");
if (config.AppSettings.Settings["WindowPositionLeft"] == null)

config.AppSettings.Settings.Add("WindowPositionLeft", currentWindowPositionLeft);

else

config.AppSettings.Settings["WindowPositionLeft"].Value = currentWindowPositionLeft;

config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sectionName);






share|improve this answer

























  • @BilalTahir I edited the answer to show this step.

    – BionicCode
    Mar 26 at 7:46













1












1








1







As others have already pointed out, you will have to store the attributes of the window to persist them between the starts. In order to set the location of the Window you have to set WindowStartupLocation to WindowStartupLocation.Manual. You would have to start the main window manually from the App.xaml.cs.



In order to change the way WPF starts your application, you have to modify the App.xaml and change the active property StartupUri to the event handler property Startup and assign a handler method to it (in this case named Run):



<Application x:Class="WpfTestRange.Main.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Run">
</Application>


Then implement the handler in the App.xaml.cs and start the main window manually:



private void Run(object sender, StartupEventArgs e)

this.MainWindow = new MainWindow();
this.MainWindow.Closing += SaveWindowAttributes;
RestoreWindow();
this.MainWindow.Show();


protected void RestoreWindow()

this.MainWindow.WindowStartupLocation = WindowStartupLocation.Manual;
var reader = new AppSettingsReader();

string windowStateValue;
try

windowStateValue = reader.GetValue("WindowState", typeof(string)) as string;

catch (InvalidOperationException)

// There are no previously persisted values (first launch)
return;


WindowState windowState;
if (!string.IsNullOrWhiteSpace(windowStateValue) && Enum.TryParse(windowStateValue, out windowState))

this.MainWindow.WindowState = windowState;


string windowTopValue = reader.GetValue("WindowPositionTop", typeof(string)) as string;
string windowLeftValue = reader.GetValue("WindowPositionLeft", typeof(string)) as string;

double windowPositionTop;
double windowPositionLeft;
if (!string.IsNullOrWhiteSpace(windowStateValue)
&& double.TryParse(windowTopValue, out windowPositionTop)
&& double.TryParse(windowLeftValue, out windowPositionLeft))

this.MainWindow.Top = windowPositionTop;
this.MainWindow.Left = windowPositionLeft;




private void SaveWindowAttributes(object sender, CancelEventArgs e)

string sectionName = "appSettings";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

string currentWindowState = this.MainWindow.WindowState.ToString();
if (config.AppSettings.Settings["WindowState"] == null)

config.AppSettings.Settings.Add("WindowState", currentWindowState);

else

config.AppSettings.Settings["WindowState"].Value = currentWindowState;


string currentWindowPositionTop = this.MainWindow.Top.ToString("G");
if (config.AppSettings.Settings["WindowPositionTop"] == null)

config.AppSettings.Settings.Add("WindowPositionTop", currentWindowPositionTop);

else

config.AppSettings.Settings["WindowPositionTop"].Value = currentWindowPositionTop;


string currentWindowPositionLeft = this.MainWindow.Left.ToString("G");
if (config.AppSettings.Settings["WindowPositionLeft"] == null)

config.AppSettings.Settings.Add("WindowPositionLeft", currentWindowPositionLeft);

else

config.AppSettings.Settings["WindowPositionLeft"].Value = currentWindowPositionLeft;

config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sectionName);






share|improve this answer















As others have already pointed out, you will have to store the attributes of the window to persist them between the starts. In order to set the location of the Window you have to set WindowStartupLocation to WindowStartupLocation.Manual. You would have to start the main window manually from the App.xaml.cs.



In order to change the way WPF starts your application, you have to modify the App.xaml and change the active property StartupUri to the event handler property Startup and assign a handler method to it (in this case named Run):



<Application x:Class="WpfTestRange.Main.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Run">
</Application>


Then implement the handler in the App.xaml.cs and start the main window manually:



private void Run(object sender, StartupEventArgs e)

this.MainWindow = new MainWindow();
this.MainWindow.Closing += SaveWindowAttributes;
RestoreWindow();
this.MainWindow.Show();


protected void RestoreWindow()

this.MainWindow.WindowStartupLocation = WindowStartupLocation.Manual;
var reader = new AppSettingsReader();

string windowStateValue;
try

windowStateValue = reader.GetValue("WindowState", typeof(string)) as string;

catch (InvalidOperationException)

// There are no previously persisted values (first launch)
return;


WindowState windowState;
if (!string.IsNullOrWhiteSpace(windowStateValue) && Enum.TryParse(windowStateValue, out windowState))

this.MainWindow.WindowState = windowState;


string windowTopValue = reader.GetValue("WindowPositionTop", typeof(string)) as string;
string windowLeftValue = reader.GetValue("WindowPositionLeft", typeof(string)) as string;

double windowPositionTop;
double windowPositionLeft;
if (!string.IsNullOrWhiteSpace(windowStateValue)
&& double.TryParse(windowTopValue, out windowPositionTop)
&& double.TryParse(windowLeftValue, out windowPositionLeft))

this.MainWindow.Top = windowPositionTop;
this.MainWindow.Left = windowPositionLeft;




private void SaveWindowAttributes(object sender, CancelEventArgs e)

string sectionName = "appSettings";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

string currentWindowState = this.MainWindow.WindowState.ToString();
if (config.AppSettings.Settings["WindowState"] == null)

config.AppSettings.Settings.Add("WindowState", currentWindowState);

else

config.AppSettings.Settings["WindowState"].Value = currentWindowState;


string currentWindowPositionTop = this.MainWindow.Top.ToString("G");
if (config.AppSettings.Settings["WindowPositionTop"] == null)

config.AppSettings.Settings.Add("WindowPositionTop", currentWindowPositionTop);

else

config.AppSettings.Settings["WindowPositionTop"].Value = currentWindowPositionTop;


string currentWindowPositionLeft = this.MainWindow.Left.ToString("G");
if (config.AppSettings.Settings["WindowPositionLeft"] == null)

config.AppSettings.Settings.Add("WindowPositionLeft", currentWindowPositionLeft);

else

config.AppSettings.Settings["WindowPositionLeft"].Value = currentWindowPositionLeft;

config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sectionName);







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 15:10

























answered Mar 25 at 7:59









BionicCodeBionicCode

1,620715




1,620715












  • @BilalTahir I edited the answer to show this step.

    – BionicCode
    Mar 26 at 7:46

















  • @BilalTahir I edited the answer to show this step.

    – BionicCode
    Mar 26 at 7:46
















@BilalTahir I edited the answer to show this step.

– BionicCode
Mar 26 at 7:46





@BilalTahir I edited the answer to show this step.

– BionicCode
Mar 26 at 7:46





Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현