This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Ivan, I need to provide a password field in the property grid. I created a property editor which just replaces the default textbox with a PasswordBox and then at runtime I got this lovely message:
Doh! I can't bind to the Password property of the PasswordBox. I'm trying to work around this by updating the field manually. I'm handling the PasswordChanged event on PasswordBox and updating my data objects accordingly, but when the selected source object changes I have to update the PasswordBox in the property grid. I'm having some trouble getting at the PasswordBox in the property grid. Can you give some guidance? So far it looks like I have to enumerate through the nodes in the grid and find the one with the right property name, then I'm not sure how to get at the PasswordBox. BTW, do you know of a better workaround for dealing with this problem?
<rant@ms> |
|
|
My suggestion offhand would be to create a custom control with a bindable (DependencyProperty-backed) Password property. For the default template of this control, use a PasswordBox. In the DP change handler of your Password property, update the template PasswordBox.Password; in OnApplyTemplate, hook the PasswordChanged event of the template PasswordBox and use it to set your Password property. Now you can databind your Password property, and your control will take care of shuttling the data back and forth to the template PasswordBox. So now you can use your custom control in the data template for the secret property of the business object. Caveat: I haven't tried this. If you prefer to stick with your current approach of catching notifications from the business object and pushing updates to a "normal" PasswordBox from your code-behind, you are right, getting at the embedded control in an editor is a bit tricky. This is because we use WPF data templates and it is quite hard to reach inside a data template instantiation. For a possible solution, have a look at the thread at http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1222: although this is talking about setting focus to a particular editor, it could easily be adapted to get a reference to the control instead, so that you can manipulate the content or otherwise party on it. It's not very pretty but it may be enough to get you through. |
|
|
Thanks... the custom control seems like the right approach and your suggestions are probably enough to get me started. Of course I have zero experience with WPF custom controls, but I'll give it a go. If it all works out I'll post some instructions for anyone else that runs into this. |
|