Unable to data-bind to a PasswordBoxWhen I attempt to bind to the Password property of the PasswordBox (binded to a property on an object that returns a string), I get the following error:<br /><br />Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.String'.<br /><br />Is string the wrong type....I tried char[] with the same result.© 2009 Microsoft Corporation. All rights reserved.Fri, 03 Jul 2009 23:04:20 Z7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5einuwanhttp://social.msdn.microsoft.com/Profile/en-US/?user=inuwanUnable to data-bind to a PasswordBoxWhen I attempt to bind to the Password property of the PasswordBox (binded to a property on an object that returns a string), I get the following error:<br /><br />Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.String'.<br /><br />Is string the wrong type....I tried char[] with the same result.Fri, 28 Oct 2005 01:30:48 Z2005-11-09T21:50:48Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#91536f8b-68e1-4c28-ab28-f878fd75fa22http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#91536f8b-68e1-4c28-ab28-f878fd75fa22Drew Marshhttp://social.msdn.microsoft.com/Profile/en-US/?user=Drew%20MarshUnable to data-bind to a PasswordBoxYou can't bind the property beause it is not a DependencyProperty. It is probably not a DP because Microsoft doesn't see any point in it being one and I'm inclined to share that perspective. In what scenario would you ever want to databind to a password box?<br /><br />HTH,<br />DrewFri, 28 Oct 2005 02:26:49 Z2005-10-28T02:26:49Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#a16f5bb3-59f5-4049-aff0-09f8ae03800chttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#a16f5bb3-59f5-4049-aff0-09f8ae03800cinuwanhttp://social.msdn.microsoft.com/Profile/en-US/?user=inuwanUnable to data-bind to a PasswordBoxI would like to bind to the Password box for the reason why you would want to data-bind anything...that is to enable the UI (XAML) to be less coupled to the application logic.&nbsp; Without binding, I would have to know the name associated with the password box and then from code get a reference to&nbsp;the password box and directly access its Password property.&nbsp; With binding, I simply know that there some data object&nbsp;bound to the page (or window, dialog, etc) and&nbsp;then&nbsp;get the&nbsp;password value from that object.Fri, 28 Oct 2005 05:15:22 Z2005-10-28T05:15:22Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#c691f641-5682-4287-aca5-7451e3b0b610http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#c691f641-5682-4287-aca5-7451e3b0b610Ben Westbrook - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Ben%20Westbrook%20-%20MSFTUnable to data-bind to a PasswordBox<p>PasswordBox.Password doesn't have a corresponding DependencyProperty, so you can't data-bind to it.<br /><br />Exposing a DependencyProperty would require us to store the PasswordBox content plain text in memory in the property system -- which is a security concern.&nbsp; The PasswordBox encrypts its content and only generates plain text on demand when a caller references the Password CLR property.<br /></p>Wed, 09 Nov 2005 17:43:49 Z2005-11-09T21:50:48Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#8216728b-138f-49da-bbc7-944a22037d6bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#8216728b-138f-49da-bbc7-944a22037d6bLeoXuehttp://social.msdn.microsoft.com/Profile/en-US/?user=LeoXueUnable to data-bind to a PasswordBox<p>Hi,</p> <p>  I want to use the Password of a PasswordBox as CommandParameter of a Button.</p> <p>  Since the Password can't be dinding, how to do so?</p> <p> </p>Wed, 06 Dec 2006 17:04:57 Z2006-12-06T17:04:57Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#dd3cc5ff-0307-4946-8120-3ced68956996http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#dd3cc5ff-0307-4946-8120-3ced68956996Samuel Jackhttp://social.msdn.microsoft.com/Profile/en-US/?user=Samuel%20JackUnable to data-bind to a PasswordBox<p>I've created a method to allow the Password on PasswordBox to be databound (using attached properties).<br><br>You can get the code here: <a href="http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html">http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html</a></p>Mon, 23 Jun 2008 09:51:31 Z2008-06-23T09:51:31Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#2c70f6f5-5dea-4e06-9fd3-906c0f24e897http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#2c70f6f5-5dea-4e06-9fd3-906c0f24e897LesterLobo - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=LesterLobo%20-%20MSFTUnable to data-bind to a PasswordBoxAs Ben mentioned, Databinding passwords is not a good design for security reasons and should be avoided.Mon, 23 Jun 2008 16:58:56 Z2008-06-23T16:58:56Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#a15b6f08-2347-4f8c-8a09-215ac4206fdbhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#a15b6f08-2347-4f8c-8a09-215ac4206fdbSamuel Jackhttp://social.msdn.microsoft.com/Profile/en-US/?user=Samuel%20JackUnable to data-bind to a PasswordBox Lester,<br>   I agree that databinding passwords sometimes isn't a good idea, but I've posted my reasons why I don't think its always a problem in this post over here: <a href="http://forums.msdn.microsoft.com/en-US/wpf/thread/d5d9c146-3379-4a1e-8671-d37367ad4906">http://forums.msdn.microsoft.com/en-US/wpf/thread/d5d9c146-3379-4a1e-8671-d37367ad4906</a>. <br><br>Could you explain further why you think it is always a bad idea? Also, is there a reason why you haven't exposed a SecureString-type property on PasswordBox, and why such a SecureString property couldn't be a dependency property?<br><br>I'd really like to understand this.<br><br>Thanks,<br><br>SamTue, 24 Jun 2008 09:27:09 Z2008-06-24T09:27:09Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#c8ec7cfb-5287-4e9c-9765-4fa08c028253http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#c8ec7cfb-5287-4e9c-9765-4fa08c028253LesterLobo - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=LesterLobo%20-%20MSFTUnable to data-bind to a PasswordBox exposing a securestring password is something that we are looking at for the current release. Sun, 29 Jun 2008 16:32:52 Z2008-06-29T16:32:52Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#e49a0753-d977-4af2-bc82-7cc7c7f3b3dfhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7ca97b60-2d8e-4a27-8c5b-b8d5d7370a5e#e49a0753-d977-4af2-bc82-7cc7c7f3b3dfYossi Starzhttp://social.msdn.microsoft.com/Profile/en-US/?user=Yossi%20StarzUnable to data-bind to a PasswordBox<p><span style="font-family:'Verdana','sans-serif';color:black;font-size:8pt">So the reason we can't bind password is security?!<br/>What about Adding a dependency property at the view and we will do binding from the View Model to the DP.<br/>the DP will be filled with the password from the password box only when we need it (when we do login or any other command that we wanted to do) and we will clear the property right after that the View Model get the password and before any other function.<br/><br/>That way we keep the view model and the view less coupled and we keep the security advantage of the Password Box.</span></p>Fri, 03 Jul 2009 23:04:20 Z2009-07-03T23:04:43Z