Are WPF Application Settings automatically saved by default when exit?
I just added a boolean to my application settings (by default is setted to false). I want to set it to true when application is running and next time when I open it again, to be false. I don't want to save my application settings. I want to be static for that boolean.
It is saving automatically?
When I used to work with VB.NET Winforms, there was a setting in Application tab, named "Save my.settings on shutdown". But, how is in WPF?
I use Visual Studio 2012, Vb.NET WPF application
Thank you
Are settings saved automatically? No, you have to explicit invoke the Save method upon each settings class.
Since you mention that you have multiple windows, then i think the quick and dirty way would be to override the OnExit Method in App:
Class Application
Protected Overrides Sub OnExit(ByVal e As ExitEventArgs)
MySettings.Default.Save()
MyBase.OnExit(e)
End Sub
End Class
Related
I need to open a winforms FolderBrowserDialog from class library. We are calling the method via web socket from js and i need to open a FolderBrowserDialog in that method in order to get path and do some operations inside the folder. I tried both opening a new winform which contains a FolderBrowserDialog and FolderBrowserDialog without form but the form is freezing and doesnt response afer show or showdialog method. Is there a proper way to do it?
Information about the arcitechture: We have a .net web socket listener app and it is already running on the client machine. Frontend requets comes in to that app an it runs c# on the clients machine using reflection class and dlls on the client machine.
I stumbled upon this problem also and noticed that when in C# winforms FolderBrowserDialog doesn't work from a class that doesn't inherit from a Form.
I put the method which uses FolderBrowserDialog in a form which I knew will be open at the time, then saved handle to this form to a place accessible from my class (i.e. static class/DI injected service etc) and called my method through that proxy.
I have windows application that used to run on a Motorola Scanner that used Windows Mobile 6.1. We upgraded the scanner to a newer model which uses Window CE 7. The application has a login form and a main form. One the user is authenticated, the login form closes and the main form opens up as expected but whenever a date is changed on the main form , the login screen reappears. Its as though login.Close() isn't really closing the login form but actually pushing it to the background and its reappearing. This application used to work fine in the older scan gun. I tried searching for specific issues but to no use.
I am not sure this is what you are looking for but you can try to set the minimizebox property to false on the form as winmobile tends to not close application but send them to background instead. With that property to false, it will close it. Although it would be interesting to see your code because calling the close() statement on the form should close it...
I need app.config automatically database informations setting according to a user control ..
Normally, we are setting up database informations in app.config. But when standart users run this program, it must login database setting on a interface . so, they should enter their database informations . not in app.config.
how should I do this?
if you are using visual studio for Windows Form Application then you can create Settings to store your different type of values in it. You can write and read settings programmatically like this.
//To Write
Properties.Settings.Default.DatabaseName = textBox1.Text;
Properties.Settings.Default.Save();
//To Read
textBox1.Text = Properties.Settings.Default.DatabaseName;
You can find article about User's Settings on MSDN
Edited
Full Example given here:
http://www.c-sharpcorner.com/UploadFile/5089e0/create-single-connection-string-for-all-windows-form-in-net/
If you are developing using DevExpress XAF, you can display a standard Windows form just before the application startup. Technically, this form can be invoked via the ShowDialog method before the winApplication.Setup() call in the Main routine (of course, the invocation must be done only if no user settings are saved yet). Once you display this dialog and gather user input, update the winApplication.ConnectionString property accordingly (see also).
Another more complex solution is to embed this database settings UI into the logon form as described at https://www.devexpress.com/Support/Center/Example/Details/E1344.
Do not hesitate to contact the DevExpress support team if you want to further discuss the implementation of this task.
I'm new to WPF and I'm working on a project that will have the following components : a WCF server class library, a WCF client class library, a WPF client UI and a WPF server UI.
I have a method in WCF client that add a user to a collection in the client and then register this user in the server. The method checks that user doesn't already exist locally then register in on the server that throws a FaultException if the user already exist on it.
How can I notify the client that operation doesn't succeed and that he must choose an other name? Throwing an exception? Adding code in ViewModel to check if user exists before calling add method?
Thank you.
IMHO, the best option is to check from the ViewModel on the server if the user already exists, if so, show a message on the UI.
Exceptions must be used for unexpected situations, and this is not the case.
A couple of ways. Take a moment to learn ValidationRules. This should help with that.
How to disable a Button on TextBox ValidationErrors in WPF
Howevever, you could do the same thing without a ValidationRule. Just have some error text that has Visibility bound to a bool in the ViewModel. Of course the error text would only be Visibile if user already exists.
Once you have looked at those two options, you should know which on is best for your project.
I am looking for a way to make my app running in a single instance mode and showing the MainWindow of the first instance when another instance is launched.
I do a quick search on the internet but I did'nt find anything to open the MainWindow of the first instance or it was for Windows Form not for WPF.
I am working in VB.Net with Framework 4 and WPF.
Thanks
I wrote up an article for Winforms a while back at http://www.thinqlinq.com/Post.aspx/Title/Single-Instance-Winform-Issue. With winforms you can use the MyApplication_StartupNextInstance event handler to intercept subsequent launch requests and redirect them (navigating back to the MainWindow?) Unfortunately, I don't see that StartupNextInstance is still available with WPF. Maybe the pre 2.0 sample I posted at http://web.archive.org/web/20060528010613/http://www.avbsg.net/Uploads/SingleInstanceVB.zip can give you an idea of how to do this with WPF. My blog post walks through the general steps that I used.