Binding to a PasswordBox (MVVM) - EASY WPF (.NET CORE)

  Рет қаралды 21,169

SingletonSean

SingletonSean

Күн бұрын

Learn how to bind to a PasswordBox by creating a custom control. One of the most frustrating issues with the WPF PasswordBox is that the Password property is not a DependencyProperty. Therefore, view models can not bind to the Password property. However, this problem is solvable by creating a custom WPF control and setting up a custom Password DependencyProperty.
SOURCE CODE: github.com/SingletonSean/wpf-...

Пікірлер: 62
@polarisnation201
@polarisnation201 2 жыл бұрын
Your video is so nice with subtitle. Thanks to you, I saved time.
@jonathancumini6183
@jonathancumini6183 Ай бұрын
Best value for this topic. Thank you so much
@lolol-kt6vp
@lolol-kt6vp Жыл бұрын
Thank you very much, simple elegant soltion!
7 ай бұрын
Sean, thanks a lot. Great tutorial, very well explained and it was just what I needed. Excellent! Thanks again.
@SingletonSean
@SingletonSean 7 ай бұрын
Thanks Marvin, glad this helped!
@MXDMND_
@MXDMND_ 4 жыл бұрын
Thanks for this tutorial so much. It was very useful for me. I shold have deeper understanding of the dependency properties since as I can see there are a lot of possibilities in the depprops. Thanks again ;)
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey Zsolt, glad the tutorial was helpful! This is definitely a good demonstration of the power of dependency properties.
@tjzIsMe
@tjzIsMe 4 жыл бұрын
Thank you for this, password boxes are pain to deal with in WPF, leading a lot of newer developers to cheat a bit to make things easier, leading to weakened security.
@SingletonSean
@SingletonSean 4 жыл бұрын
Definitely Joe! Glad I'm not the only one who's experienced this. I'm also guilty of cheating around it in the past, hahaha.
@mirko7389
@mirko7389 3 жыл бұрын
@@SingletonSean doesn't this solution weaken security also by exposing password ?
@jacemalloy5160
@jacemalloy5160 2 ай бұрын
Simple and functional. Thanks man!
@marioilsanker4307
@marioilsanker4307 4 жыл бұрын
Excellent tutorial and a very nice solution! Thank you very much for sharing!
@marioilsanker4307
@marioilsanker4307 4 жыл бұрын
On a second thought though, maybe it would be a good point to have the _password backing field within the ViewModel to be a System.Security.SecureString to avoid having the password stored as plaintext in memory? I guess this is even the reason why PasswordBoxes do not offer a string Binding per default?
@edgarsarkisyan6422
@edgarsarkisyan6422 2 жыл бұрын
Thanks a lot my brother, your tutotial helped me with this spooky PasswordBox binding. Big lOVE
@SingletonSean
@SingletonSean 2 жыл бұрын
Certainly spooky! Glad this was helpful Edgar
@kennethgrande5749
@kennethgrande5749 Жыл бұрын
Great video Sean 👍
@BrankoTheDefender
@BrankoTheDefender 11 ай бұрын
Thank you. You are the best!
@julianoleicam
@julianoleicam Жыл бұрын
Thanks for this video, i'am implemented this to solved a issue task.
@dino633
@dino633 2 жыл бұрын
Good video! Thanks a lot!
@matk5087
@matk5087 3 жыл бұрын
U saved me!!!! THX
@SoloEnLaCasa
@SoloEnLaCasa 2 жыл бұрын
Hi Sean Thank you very much for helping the community to understand more about WPF with MVVM. excellent video to understand Binding PasswordBox in WPF with MVVM could you extend the application, so that when the password is inserted, each inserted character is showed for a short time? or a button to show all characters the inserted password? take care and stay healthy
@popadicm7021
@popadicm7021 3 ай бұрын
Thanks legend
@toddnedd2138
@toddnedd2138 10 ай бұрын
It is a solution, thanks for providing it. I prefer a solution using a behavior, it is almost the same code with a dp, but you can get rid of the combined control xaml and have only a clean cs file.
@HaiAek
@HaiAek 3 жыл бұрын
Thank you
@dannyklee1134
@dannyklee1134 Жыл бұрын
Hi Sean Your example is great. But how can I completely select the content of the "GotFocus-Event"?
@noahyannis2465
@noahyannis2465 2 жыл бұрын
So when I want to bind the content of a TextBox to a Property in the view model, I have to create a new, special TextBox control class?
@brandonberisford
@brandonberisford 3 жыл бұрын
Sean can you make this control for the .NET Framework as well?
@longuinni
@longuinni 3 жыл бұрын
Really nice tutorial!!! But seriously Microsoft, WHY??? A suggestion for the next WPF video: INotifyDataErrorInfo with complex object, not just a simple property.
@SingletonSean
@SingletonSean 3 жыл бұрын
Haha exactly Fernando! INotifyDataError is a great topic I'd like to cover. Thanks for the suggestion.
@RealBadCharlie
@RealBadCharlie 4 жыл бұрын
In MHO the DependencyProperty system is by far the most powerful feature of WPF.
@SingletonSean
@SingletonSean 4 жыл бұрын
Definitely Charlie! I love dependency properties and they open up so many opportunities for creating rich and reusable components. Sometimes I feel like they don't get as much love/respect since there's so much boilerplate code associated with adding one. Of course, snippets take care of this problem. It would be nice to have it as simple as "props" in JS frameworks like React or Vue. Maybe I'll work on some kind of package to accomplish that functionality, haha.
@shakrazj
@shakrazj 2 жыл бұрын
hello friend. I get a XDG0062 error: Default value type does not match type of property 'Password'.. I can't see how it wouldn't. Anything come to mind that could be the cause of this?
@hohojimmy4443
@hohojimmy4443 3 жыл бұрын
Useful!
@SingletonSean
@SingletonSean 3 жыл бұрын
Good to know, thanks hoho!
@fsl1209
@fsl1209 3 ай бұрын
I cant get my bindablepasswordbox to be supported in the xaml of my loginview, no matter how i use namespaces?
@SuperArbalest
@SuperArbalest 4 жыл бұрын
Thanks for your tutorial! Sean, May you make a series about Reactive Extension Package,please? Thank you!
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey SuperArbalest, I'd love to do videos on this! I've only used reactive extensions once or twice, so I'm not super experienced with them. From reading the documentation in the past, I can tell they are extremely useful! Looking forward to add this to my tookit.
@davidos533
@davidos533 2 жыл бұрын
Awesome
@user-gt2wc2eg1i
@user-gt2wc2eg1i 3 жыл бұрын
Спасибо!
@jozefvendel1831
@jozefvendel1831 4 ай бұрын
If I enter the wrong password, how is it possible to delete the Passwordbox in the UI? is it necessary to reload LoginView?
@richardhrban8707
@richardhrban8707 3 жыл бұрын
Sean, when I try to set Template property in Style, I cant type in nothing, when I switch to standard passwordBox, with exactly same style, it is working fine.
@richardhrban8707
@richardhrban8707 3 жыл бұрын
I tried to use your NuGet PasswordBox, so it is valid for that, also I cant bind IsFocused for default text, so I ends up with create my own UserControl where I need to handle also focus.
@VinuP2023
@VinuP2023 4 жыл бұрын
Thank much Sean :) Sean, I have one question. Canyou please explain what is callback and why we need it,how we achieve it using delegates. I watcher many tutorials and I don't seem to get it :)
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey Vinay, callbacks are important for handling events. Using events is useful for decoupling code and communicating between different objects. The best way to learn is by playing around with them in your own environment :) I will admit when I started programming and first learned about events, it was definitely a weird topic to wrap my head around at first. As always, with enough practice it will eventually click!
@avatar-kf1ii
@avatar-kf1ii 4 жыл бұрын
That's nice. I cheat by setting a value on view model from the view's code behind. Like: ((dynamic)DataContext).Pass = (sender as PasswordBox).Password;
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks avatar! Haha, everyone has a different hack to get around this issue. That's pretty hardcore, lol.
@riyadamrani
@riyadamrani 3 жыл бұрын
I Sean wouldn't that be a security concern to keep the password non encrypted on the memory like this ? MessageBox was propably made so you pass that PasswordBox.Password straight to the encryption command.
@SingletonSean
@SingletonSean 3 жыл бұрын
Hey Riyad, I'm not sure it's too dangerous. Considering I can retrieve the PasswordBox.Password in my application in plain text, I would assume a hacker could too. Additionally, if a hacker has trespassed into the user's PC memory, then the hacker is probably also capable of logging the user's keystrokes and obtaining the password in that manner too (or just opening the users "password.txt" file on their desktop, right? Hahaha). Definitely a great question and a valid concern to have though!
@riyadamrani
@riyadamrani 3 жыл бұрын
@@SingletonSean Thank you for the response! I am also addicted to the full stack MVVM serie so I am looking forward for the next episode 😂
@solver9113
@solver9113 2 жыл бұрын
Hello, billions thanks to your tutorial, can you pls tell me how to set "CaretBrush" property for this BindablePasswordBox?
@solver9113
@solver9113 2 жыл бұрын
Thanks, I dealed with it
@user-gt2wc2eg1i
@user-gt2wc2eg1i 3 жыл бұрын
Кстати некорректно работает если во Frame открывать страницу повторно, то затирается приватная переменная пароля. Почему? Как исправить? Пришлось каждый раз создавать страницу чтобы показать ее во Frame
@bulsond
@bulsond 3 жыл бұрын
Страницами и фреймом лучше вообще не пользоваться. Вместо страниц надо использовать UserControl, а для отображения в окне использовать
@gregorjrgensen1466
@gregorjrgensen1466 3 жыл бұрын
For some reason Password in my viewmodel is getting nullified when I activate the command - public ICommand LoginCommand { get { return new BaseCommand(ClickLogin); } } private async void ClickLogin() { IsEnabled = false; UserName = _username; Password = _password; // change this to incorporate hash and verify ShowMessageBox(Password); BaseCommand: internal class BaseCommand : ICommand { private readonly Action command; private readonly Func canExecute; public BaseCommand(Action command, Func canExecute = null) { this.canExecute = canExecute; this.command = command ?? throw new ArgumentNullException("command"); } public void Execute(object parameter) { command(); } public bool CanExecute(object parameter) { if (canExecute == null) return true; return canExecute(); } public event EventHandler CanExecuteChanged; } any idea what's happening there?
@VinuP2023
@VinuP2023 4 жыл бұрын
Hello Sean, a request video please: use of partial class in a real time scenario. I know partial classes are there in code behind of Win forms and WPF XAML, but do we ever need to create a partial class for some use case.
@SingletonSean
@SingletonSean 3 жыл бұрын
Hey Vinay, I personally don't like to create partial classes. I've had weird scenarios in the past where I've wondered "where is this function/variable?" only to realize I was in a partial class and the function/variable was in another partial class. However, if you want to split up a class across multiple files, partial classes are a good solution. Just don't make your entire application one gigantic partial class hahaha.
@VinuP2023
@VinuP2023 3 жыл бұрын
Sean, thank you for the suggestion ☺️
@HackelSchorsch
@HackelSchorsch 10 ай бұрын
It is so unbelivable that this is still an issue and there is still no offical solution for this.
@SingletonSean
@SingletonSean 10 ай бұрын
Seriously, it is fixed in .NET MAUI though!
@ivandrofly
@ivandrofly Жыл бұрын
Another issue with password box can be learn in kzbin.info/www/bejne/qqO1ZoWHfKqnm68
@neriacohen5490
@neriacohen5490 2 жыл бұрын
the version of 2022 SUCKS! Do not! download!!!!!!!!!! only 2021 and below.
Async Commands (and Async Relay Command) - EASY WPF (.NET CORE)
14:14
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 118 М.
Why Is He Unhappy…?
00:26
Alan Chikin Chow
Рет қаралды 67 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 18 МЛН
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 37 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 11 МЛН
Microsoft Is KILLING Windows | ft. Steve @GamersNexus
19:19
Level1Techs
Рет қаралды 281 М.
Password Storage Tier List: encryption, hashing, salting, bcrypt, and beyond
10:16
How to Store and Retrieve Setting  In WPF
28:05
Tactic Devs
Рет қаралды 11 М.
Creating Reusable Controls - WPF TUTORIALS
17:10
SingletonSean
Рет қаралды 30 М.
How to Hash Passwords with BCrypt in C#
9:00
Claudio Bernasconi
Рет қаралды 8 М.
Is LEARNING WPF still WORTH it in 2023?
10:59
tutorialsEU
Рет қаралды 44 М.
The Easiest Way to Create PDFs in .NET
9:47
Nick Chapsas
Рет қаралды 110 М.
Switching Between Multiple Views in MVVM - EASY WPF (.NET CORE)
12:29
Better Than Smart Phones☠️🤯 | #trollface
0:11
Not Sanu Moments
Рет қаралды 18 МЛН
Частая ошибка геймеров? 😐 Dareu A710X
1:00
Вэйми
Рет қаралды 5 МЛН
📱магазин техники в 2014 vs 2024
0:41
djetics
Рет қаралды 646 М.
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18
Ускоряем ваш TV🚀
0:44
ARTEM_CHIBA
Рет қаралды 196 М.