Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation doesnt work (message doesnt show) #23

Closed
Rainson12 opened this issue Apr 15, 2018 · 2 comments
Closed

validation doesnt work (message doesnt show) #23

Rainson12 opened this issue Apr 15, 2018 · 2 comments

Comments

@Rainson12
Copy link

Rainson12 commented Apr 15, 2018

Im trying to add validation to your sample but the validation message doesnt show. The validation executes but the validation message will never be shown. This seems to be an issue of the WindowChrome.WindowChrome stuff in the MainWindow. If i remove the WindowChrome stuff the validation message shows up. Heres an example:

<TextBox x:Name="NameTextBox" VerticalAlignment="Top"> <TextBox.Text> <Binding Path="FirstName" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <validations:NotEmptyValidationRule ValidatesOnTargetUpdated="True" /> </Binding.ValidationRules> </Binding> </TextBox.Text> <Validation.ErrorTemplate> <ControlTemplate> <StackPanel> <!-- Placeholder for the TextBox itself --> <AdornedElementPlaceholder x:Name="textBox"/> <TextBlock Text="{Binding [0].ErrorContent}" Foreground="Red"/> </StackPanel> </ControlTemplate> </Validation.ErrorTemplate> </TextBox>

public class NotEmptyValidationRule : ValidationRule { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { var test = string.IsNullOrWhiteSpace((value ?? "").ToString()) ? new ValidationResult(false, "Field is required.") : ValidationResult.ValidResult; return test; } }

@Rainson12
Copy link
Author

a fix would be to change the PageHost.xaml to
<AdornerDecorator> <Grid> <ContentControl x:Name="OldPage" /> <ContentControl x:Name="NewPage" /> </Grid> </AdornerDecorator>

@angelsix
Copy link
Owner

image

Works fine without any changes to latest source code

   <!-- Email -->
    <TextBox 
                Tag="Email"
                local:IsFocusedProperty.Value="True"
                >
        <TextBox.Text>
            <Binding Path="Email" UpdateSourceTrigger="PropertyChanged">
                <Binding.ValidationRules>
                    <local:NotEmptyValidationRule ValidatesOnTargetUpdated="True" />
                </Binding.ValidationRules>
            </Binding>
        </TextBox.Text>
        <Validation.ErrorTemplate>
            <ControlTemplate>
                <StackPanel>
                    <!-- Placeholder for the TextBox itself -->
                    <AdornedElementPlaceholder x:Name="textBox"/>
                    <TextBlock Text="{Binding [0].ErrorContent}" Foreground="Red"/>
                </StackPanel>
            </ControlTemplate>
        </Validation.ErrorTemplate>
    </TextBox>

No repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants