문제

In my Metadata class, there is a class Person with the following property:

Public Property Name As String

In my entity model, this property has Nullable set to False. I bind the Name of a new Person to a TextBox on my Silverlight app. When blank, the border of the box turns red and an error message hovers saying "The Name field is required".

I want the border to go red, but I dont want an error message to hover. How can I achieve this?

I've tried an attribute of

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

But the message still shows.

도움이 되었습니까?

해결책

If the validation state is displayed at the correct time, but you do not want to show the validation message, you must modify the control template for your text box.

By default, the TextBox Control Template has a Border named ValidationErrorElement. That Border has a Tooltip which shows the error message. You just need to remove the tooltip.

<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>

Then apply the template to your TextBox

<TextBox Template="{StaticResource customTextBox}" ... />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top