我在验证错误模板和样式上有一个 XamlParseException。
我不知道问题是什么。
xml:
<DataGridTemplateColumn Header="Naam"
CellTemplate="{StaticResource ContactNameTemplate}"
CellEditingTemplate="{StaticResource EditingContactNameTemplate}"/>
字典:
<DataTemplate x:Key="ContactNameTemplate">
<TextBox HorizontalAlignment="Center"
Validation.ErrorTemplate="{StaticResource validationTemplate}"
Style="{StaticResource textBoxInError}">
<TextBox.Text>
<Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<c:Text Min="21" Max="130"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</DataTemplate>
<DataTemplate x:Key="EditingContactNameTemplate">
<TextBox HorizontalAlignment="Center"
Validation.ErrorTemplate="{StaticResource validationTemplate}"
Style="{StaticResource textBoxInError}">
<TextBox.Text>
<Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<c:Text Min="21" Max="130"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</DataTemplate>
<ControlTemplate x:Key="validationTemplate">
<DockPanel>
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
<AdornedElementPlaceholder/>
</DockPanel>
</ControlTemplate>
<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
模型:
public class Text : ValidationRule
{
private int _min;
private int _max;
public Text()
{
}
public int Min
{
get { return _min; }
set { _min = value; }
}
public int Max
{
get { return _max; }
set { _max = value; }
}
public override ValidationResult Validate(object value,
System.Globalization.CultureInfo cultureInfo)
{
ValidationResult result;
string text;
if (((string)value).Length < Min || ((string)value).Length > Max)
{
text = value.ToString();
result = new ValidationResult(true, null);
}
else
{
text = "";
result = new ValidationResult(false,
"De naam moet tss " + Min + " en " + Max + " liggen.");
}
return result;
}
}
我得到的错误
类型的第一次机会异常'System.Windows.Markup.XamlParseException'
发生在PresentationFramework.dll
.
附加信息:指定的值System.Windows.Markup.StaticResourceHolder
引发了异常。
谢谢