Click here to Skip to main content
15,891,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code for Validation.ErrorTemplate:

<Style TargetType="{x:Type TextBox}">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Bottom" Foreground="Red" HorizontalAlignment="Center"
FontSize="14" FontWeight="Bold"  Margin="5,0,0,0" ToolTip="{Binding ElementName=adornerPlaceholder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">{0}</TextBlock>
                            <AdornedElementPlaceholder Name="adornerPlaceholder"></AdornedElementPlaceholder>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>



The second part of code, property is:

public string PassWord
{
get { return _passWord; }
set
{
if (_passWord == value)
{
return;
}
_passWord = value;

List<string> errors = new List<string>();


bool valid = true;

if (value == null || value == "")
{
errors.Add("Password can not be empty.");
SetErrors("PassWord", errors);
valid = false;
}


if (valid)
{
ClearErrors("PassWord");
}

OnPropertyChanged(new PropertyChangedEventArgs("PassWord"));
}
}



It works perfectly, but what I want to achieve is how to have full text of error message bellow text box in which data were entered and recognized in my error collection as incorrect?

So, just to have text instead of * and that text should be able to be changed depending on different textbox, as I have many fields to be entered

What I have tried:

Investigated on the net but without success.
Posted
Updated 22-Jun-19 8:41am
Comments
Richard MacCutchan 22-Jun-19 5:18am    
"It works perfectly"
Obviously not.
Afzaal Ahmad Zeeshan 22-Jun-19 5:38am    
A very simple way to do this would be by use of multiple controls in a single user control. Easier to develop, cleaner to maintain and debug.
Sinisa Janjetovic 22-Jun-19 10:37am    
If you can send me a sample?
BillWoodruff 22-Jun-19 18:09pm    
see if using ToolTips could meet your needs:

https://wpf-tutorial.com/control-concepts/tooltips/

1 solution

One typically implements the IDataErrorInfo interface which uses borders and tooltips to communicate data errors.

How to: Implement Validation Logic on Custom Objects | Microsoft Docs[^]

(Messages would obscure the UI otherwise).
 
Share this answer
 
Comments
BillWoodruff 22-Jun-19 18:14pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900