It seems that WPF has some validation rule which is turned on by default. When I enter non numeric text into the bound textbox and tab out it, a read border shows around it. What is going on here? I Have set ValidatesOnExceptions to false, where is the validation rule coming from? I am using version 4.5.2 of the .Net framework.
Here is my XAML
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication2"
mc:Ignorable="d"
Title="MainWindow" Height="159.206" Width="193.953">
<Grid>
<TextBox x:Name="textBox" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" TextWrapping="Wrap"
Text="{Binding Foo, ValidatesOnExceptions=False, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
Width="91" Margin="10,10,0,0"/>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="23" Margin="10,48,0,0"
TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="91"/>
</Grid>
</Window>
Here is the code behind
namespace WpfApplication2
{
public partial class MainWindow : Window
{
public int Foo { get; set; } = 42;
public MainWindow()
{
InitializeComponent();
}
}
}