locked
how to set a textbox to a password box? RRS feed

  • Question

  • Hello ALL.

    i have a quession,i don't want show what's write in the textbox,can LS should set zhe sytle of the textbox?how?

    Thursday, April 14, 2011 1:39 AM

Answers

  • Hi,

    As far as I know, there's nothing built into LS that will allow you do do this.

    You'd have to create your own custom control, but you'll need at least VS 2010 Professional, or above. If you're only using LightSwitch by itself, you won't be able to create custom controls. You can USE custom controls, you just won't be able to create any yourself.

    http://blogs.msdn.com/b/lightswitch/archive/2011/01/13/using-custom-controls-to-enhance-lightswitch-application-ui-part-1.aspx

    Once you've created your custom control (& what you want is going to be a very simple control to create if you have any WPF or SL experience), just follow the instructions in the article above. It's a very good article for knowledge anyway.

    In future versions of LS, I think the team has indicated that they will introduce some way of formatting controls better than what is available now, & I imagine that passwords would be one of those scenarios.

    Yann

    • Proposed as answer by Yann Duran Thursday, April 14, 2011 2:07 AM
    • Marked as answer by just a student Thursday, April 14, 2011 2:47 AM
    Thursday, April 14, 2011 2:07 AM

All replies

  • Hi,

    As far as I know, there's nothing built into LS that will allow you do do this.

    You'd have to create your own custom control, but you'll need at least VS 2010 Professional, or above. If you're only using LightSwitch by itself, you won't be able to create custom controls. You can USE custom controls, you just won't be able to create any yourself.

    http://blogs.msdn.com/b/lightswitch/archive/2011/01/13/using-custom-controls-to-enhance-lightswitch-application-ui-part-1.aspx

    Once you've created your custom control (& what you want is going to be a very simple control to create if you have any WPF or SL experience), just follow the instructions in the article above. It's a very good article for knowledge anyway.

    In future versions of LS, I think the team has indicated that they will introduce some way of formatting controls better than what is available now, & I imagine that passwords would be one of those scenarios.

    Yann

    • Proposed as answer by Yann Duran Thursday, April 14, 2011 2:07 AM
    • Marked as answer by just a student Thursday, April 14, 2011 2:47 AM
    Thursday, April 14, 2011 2:07 AM
  • thanks Duran,you give me a so detailed answer ^_^
    Thursday, April 14, 2011 2:50 AM
  • Expanding upon Yann's suggestion, you could use the inbuilt PasswordBox control which is found in System.Windows.Control.

    This would save you the effort of having to roll out your own custom control.

    After adding your password field onto your screen, change the control to a custom control and select System.Windows.Control > PasswordBox. You can then handle the lost focus event to save the contents into your entity.

    For anyone interested, I've documented the steps in more detail here.

    http://dotnettim.wordpress.com/2011/04/14/lightswitch-creating-a-masked-password-textbox-control/

     

    • Proposed as answer by Yann Duran Thursday, April 14, 2011 11:45 PM
    Thursday, April 14, 2011 5:04 PM
  • Hi Tim,

    That's where I was heading with my suggestion, but I thought you'd have to wrap the Password Box control in a custom control in order to make use of it, I didn't realise you could use a System.Wondows.Control control itself as a custom control.

    Thanks for the extra information, I've learned something useful!

    If I understand correctly, from your excellent post, you can't "bind" the control in the normal way & have to get at the value from event handlers? What about an "initial" value? (Obviously not for a password box, but if this technique was used for a different control)

    Yann

    Thursday, April 14, 2011 11:45 PM
  • I assume that in the same way one should be able to add most of the controls found in the various assemblies which is indeed very large. I tried to use the web browser control in Beta1 as a custom control and I did not know hwo to proceed, does sit work in beta2 as a custom control?
    mysorian
    Friday, April 15, 2011 3:33 AM
  • Excellent stuff Tim.

    Few days back I tried this, but didn't know how to keep the value on it.

    Thanks! 


    -Bala
    Friday, April 15, 2011 4:31 AM
  • Just a quick update to this thread. Following Yann's comment, I've worked out the data binding syntax and have updated my post to reflect this.

    In reply to Jayaram, the Web Browser control works fine in Beta2 and I've added some notes here:

    http://dotnettim.wordpress.com/2011/04/17/lightswitchdisplaying-web-pages-html-on-a-screen/

     

    Sunday, April 17, 2011 9:14 PM
  • Hi Tim,

    Thanks for taking the time to figure that out. Your previous post only had only had a link to your original method, so I'll add a direct link here to the updated version.

    http://dotnettim.wordpress.com/2011/04/17/lightswitch-creating-a-masked-password-textbox-part-2/

    So, the binding is still done in code, not in the designer (unfortunately), but as you say it's a much simpler & cleaner way of doing it than the previous method. I guess it's not that big a hassle really, when you take into account all the potential controls you get access to in System.Windows.Controls.

    Thanks again,

    Yann

    Sunday, April 17, 2011 11:28 PM