The main reason I did it this way was because you cannot use databinding to get the password from a passwordbox due to security reasons. UpdateStatusBar("Success! Your MAC address(es) were successfully exported!") Writer.WriteLine(address.PhysicalAddresses) Ĭonsole.WriteLine("The file was not written.") Using (StreamWriter writer = new StreamWriter(fileName, true))įor (int i = 0 i < i ) String fileName = folder "\\" location ".txt" Binding to a PasswordBox (MVVM) - EASY WPF (.NET CORE) SingletonSean 14.3K subscribers Join Subscribe 14K views 2 years ago WPF Tutorials Learn how to bind to a PasswordBox by creating a. Using (new NetworkConnection(folder, credentials))įoreach (string location in LocationsPicked) Private void WriteToNetworkFolder(string folder, NetworkCredential credentials) Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString) Return Marshal.PtrToStringUni(unmanagedString) UnmanagedString = Marshal.SecureStringToGlobalAllocUnicode(password) Private string ConvertToUnsecureString(SecureString password) WriteToNetworkFolder(folder, credentials) Var password = ConvertToUnsecureString(securePassword) About your requirement, the code snippet shows that the ContextMenu is assigned to the RadGridView. The solution is not MVVM, but it doesnt break the pattern and also its idea is not to be MVVM, since this will couple it with the view model in this concrete example. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. The idea is to be able to use it any data items you have in the view model. So when you try to bind the password, you'll get this error: A 'Binding' cannot be set on the 'Password' property of type 'PasswordBox'. Var securePassword = passwordContainer.Password The problem is that Password doesn't have a DependencyProperty. If (passwordContainer != null
0 Comments
Leave a Reply. |