how to minimum text length in textbox in csharp

Code Example - how to minimum text length in textbox in csharp

                
                        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
    if (((TextBox)sender).Text.Length < 5)
    {
        MessageBox.Show("You need to write at least 5 characters");
    }
}