views:

263

answers:

0

Hi

If I put a large text box which has has a data binding validation error into a ScrollViewer, the red border which is shown around the text box only includes its visible parts as if it would not be scrolled.

Example:

Window1.xaml:

<Window x:Class="ErrorTemplateApplication.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ErrorTemplateApplication"
    Title="Window1" Height="300" Width="300"
    Name="thisWindow">
    <Grid>        
        <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalAlignment="Top">
            <TextBox Width="1500" Margin="10">
                <TextBox.Text>
                    <Binding ElementName="thisWindow"
                             Path="Title"
                             UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <local:FailValidationRule ValidationStep="UpdatedValue" />
                        </Binding.ValidationRules>
                    </Binding>                    
                </TextBox.Text>
                <!-- Same result with a custom ErrorTemplate
                <Validation.ErrorTemplate>
                    <ControlTemplate>
                        <Border BorderBrush="Red" BorderThickness="2">
                            <AdornedElementPlaceholder />
                        </Border>
                    </ControlTemplate>
                </Validation.ErrorTemplate>-->
            </TextBox>
        </ScrollViewer>
    </Grid>
</Window>

FailValidationRule.cs:

class FailValidationRule : ValidationRule
{
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        return new ValidationResult(false, "Always invalid");
    }
}

If you change the value of the text box and scroll the ScrollViewer you will notice, that the red border is not as large as the text box (tested on .NET 3.5 SP1, Windows 7).

Is there any way to change this behavior?

Thank you for any answers!