Textbox绑定非string类型,为空会出现红框.失去焦点也会出现红框.用下面方法就不会出现红框,也不会出现xaml绑定错误了.
xmlns:sys="clr-namespace:Systemp;assembly=mscorlib"
<TextBox Style={StaticResource IntText} Text="{Binding Int,TargetNullValue={x:Static sys:String.Empty}}" />
<Style x:Key="IntText" TargetType="TextBox" BasedOn="{StaticResource GrayBackTextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<ControlTemplate.Resources>
<BooleanToVisibilityConverter x:Key="converter" />
</ControlTemplate.Resources>
<DockPanel LastChildFill="True">
<Border BorderThickness="1" BorderBrush="#00000000"
Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource converter}}">
<AdornedElementPlaceholder x:Name="placeholder" />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="InputMethod.IsInputMethodEnabled" Value="False"/>
<EventSetter Event="KeyDown" Handler="IntStyle_KeyDown"/>
</Style>
936

被折叠的 条评论
为什么被折叠?



