2013-03-23 56 views
0

在我Metadata类,还有一类Person具有以下属性:隐藏验证错误

Public Property Name As String 

在我的实体模型,这个属性Nullable设置为False。我在我的Silverlight应用程序中绑定了新的PersonNameTextBox。空白时,框的边框变为红色,并且错误信息悬停显示“姓名字段是必需的”。

我想让边框变红,但我不想让一个错误信息悬停。我该如何做到这一点?

我试过的

<Required(allowemptystrings:=False, ErrorMessage:=Nothing)>

属性但该消息仍显示。

回答

0

如果验证状态在正确的时间显示,但您不想显示验证消息,则必须修改您的文本框的控件模板。

默认情况下,TextBox控件模板具有一个名为ValidationErrorElement的边框。该边框具有显示错误消息的工具提示。你只需要删除工具提示。

<ControlTemplate TargetType="TextBox" x:Name="customTextBox"> 
    <Grid x:Name="RootElement"> 
     <VisualStateManager.VisualStateGroups> 
      ... 
     </VisualStateManager.VisualStateGroups> 
     ... 
     <Border x:Name="ValidationErrorElement" BorderThickness="1" CornerRadius="1" BorderBrush="#FFDB000C" Visibility="Collapsed"> 
      <!-- Remove the tooltip here --> 

      <!-- 
      <ToolTipService.ToolTip> 
       <ToolTip x:Name="validationTooltip" ... 
       </ToolTip> 
      </ToolTipService.ToolTip> 
      --> 

      <Grid Width="12" Height="12" HorizontalAlignment="Right" Margin="1,-4,-4,0" VerticalAlignment="Top" Background="Transparent"> 
       <Path Margin="1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C"/> 
       <Path Margin="1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff"/> 
      </Grid> 
     </Border> 
    </Grid> 
</ControlTemplate> 

然后模板应用到您的文本框

<TextBox Template="{StaticResource customTextBox}" ... />