I have a passwordbox implemented as a custom control as show below. I am having difficult adding validation which needs to check if the password is empty. If it is then i would need to display a message stating "Please enter a password"
<UserControl x:Class="Controls.MyPasswordBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<UserControl.Resources>
</UserControl.Resources>
<PasswordBox Name="MyPasswordBoxControl"
DataContext="{Binding Path=MyPasswordBoxControl, Mode=TwoWay}"></PasswordBox>
My code behind is as follows:
using System.Windows;
using System.Windows.Controls;
namespace Client.Controls
{
public partial class MyPasswordBox : UserControl
{
public MyPasswordBox()
{
InitializeComponent();
MyPasswordBoxControl.PasswordChanged += delegate
{
Value = MyPasswordBoxControl.Password;
};
if (!MyPasswordBoxControl.IsLoaded)
{
MyPasswordBoxControl.Loaded += delegate
{
MyPasswordBoxControl.Password = Value;
};
}
}
public string Value
{
get { return (string)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(string), typeof(MyPasswordBox), new PropertyMetadata(""));
}
}
How can i add validation which will check if the password box is empty or not?
Thanks in advance