WPF、Validation.ErrorTemplate和Windows Phone
我正在开发一个Windows Phone应用程序,需要验证文本框中的一些用户输入。以下是其中一个文本框的XAML:WPF、Validation.ErrorTemplate和Windows Phone,wpf,windows-phone-7,mvvm,Wpf,Windows Phone 7,Mvvm,我正在开发一个Windows Phone应用程序,需要验证文本框中的一些用户输入。以下是其中一个文本框的XAML: <TextBox Name="times" Grid.Row="1" Height="80" Text="{Binding UpdateSourceTrigger=Explicit, Mode=TwoWay, Path=orari, ValidatesOnDataErrors=True, ValidatesOnExc
<TextBox
Name="times"
Grid.Row="1"
Height="80"
Text="{Binding UpdateSourceTrigger=Explicit,
Mode=TwoWay,
Path=orari,
ValidatesOnDataErrors=True,
ValidatesOnExceptions=True,
NotifyOnValidationError=true}"
TextChanged="TextBoxChangedHandler"
/>
使用断点,我确信IDataError会找到错误,但文本框外观不会改变。我已经读过,我应该在XAML中使用Validate.ErrorTemplate,但是我没有找到这个选项,因为它在Windows Phone中不存在?如果输入无效,如何更改文本框的样式?
谢谢从您发布的内容很难判断,但下面是我的一些代码的一个示例,它做了一些非常类似的事情,也许可以帮助您定位错误 我想要验证的文本框所使用的样式在发生错误时会得到一个红色框
<Style x:Key="ValidationTextBox" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
如果出现错误,你有什么风格可以做一些不同的事情吗?WindowsPhone7.5发行版有一些很好的验证示例。
<TextBox Style="{StaticResource ValidationTextBox}">
<TextBox.Text>
<Binding Path="Description" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<rules:MandatoryInputRule ValidatesOnTargetUpdated="True" />
<rules:IllegalCharsRule ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>