2013-03-23 52 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}" ... />