ValidationRule.ValidationStep プロパティ


検証規則を実行するタイミングを取得または設定します。Gets or sets when the validation rule runs.

 property System::Windows::Controls::ValidationStep ValidationStep { System::Windows::Controls::ValidationStep get(); void set(System::Windows::Controls::ValidationStep value); };
public System.Windows.Controls.ValidationStep ValidationStep { get; set; }
member this.ValidationStep : System.Windows.Controls.ValidationStep with get, set
Public Property ValidationStep As ValidationStep



列挙値の 1 つ。One of the enumeration values. 既定では、 RawProposedValueです。The default is RawProposedValue.

次の例では、を ValidationStep 呼び出したときにをに設定し ConvertedProposedValue ValidationRule ValidateDateAndPrice ます。これにより、メソッドは、 Validate ソースプロパティの型の値にアクセスできるようになります。The following example sets the ValidationStep to ConvertedProposedValue on the ValidationRule called ValidateDateAndPrice so that when it runs, the Validate method has access to values that are of the source property's type. ルールとを PriceIsAPositiveNumber 実行すると FutureDateRule 、各メソッドの値は Validate 文字列になります。これは、値がそれぞれの型に変換される前にルールが実行されるためです。When the rules PriceIsAPositiveNumber and FutureDateRule run, the values in each Validate method are strings because the rules run before the values are converted to their respective types.

<StackPanel Name="stackPanel1"  Margin="10" Width="250"

    <Style TargetType="HeaderedContentControl">
      <Setter Property="Margin" Value="2"/>
      <Setter Property="Focusable" Value="False"/>
      <Setter Property="Template">
          <ControlTemplate TargetType="HeaderedContentControl">
            <DockPanel LastChildFill="False">
              <ContentPresenter ContentSource="Header" DockPanel.Dock="Left" Focusable="False" VerticalAlignment="Center"/>
              <ContentPresenter ContentSource="Content" Margin="5,0,0,0" DockPanel.Dock="Right" VerticalAlignment="Center"/>


    <Style TargetType="Button">
      <Setter Property="Width" Value="100"/>
      <Setter Property="Margin" Value="10,15,15,15"/>


    <BindingGroup NotifyOnValidationError="True">
        <src:ValidateDateAndPrice ValidationStep="ConvertedProposedValue" />
  <TextBlock FontSize="14" Text="Enter an item for sale"/>
  <HeaderedContentControl Header="Description">
    <TextBox Width="150" Text="{Binding Path=Description, Mode=TwoWay}"/>
  <HeaderedContentControl Header="Price">
    <TextBox Name="priceField"  Width="150">
        <Binding Path="Price" Mode="TwoWay" >
  <HeaderedContentControl Header="Date Offer Ends">
    <TextBox Name="dateField" Width="150" >
        <Binding Path="OfferExpires" StringFormat="d" >
  <StackPanel Orientation="Horizontal">
    <Button IsDefault="True" Click="Submit_Click">_Submit</Button>
    <Button IsCancel="True" Click="Cancel_Click">_Cancel</Button>
  <HeaderedContentControl Header="Description">
    <TextBlock Width="150" Text="{Binding Path=Description}"/>
  <HeaderedContentControl Header="Price">
    <TextBlock Width="150" Text="{Binding Path=Price, StringFormat=c}"/>
  <HeaderedContentControl Header="Date Offer Ends">
    <TextBlock Width="150" Text="{Binding Path=OfferExpires, StringFormat=d}"/>

次の例は、を示して ValidationRule ValidateDateAndPrice います。The following example shows the ValidationRuleValidateDateAndPrice. メソッドの Validate オーバーライドでは、 Price プロパティは型で Double あり、 OfferExpires プロパティは型です DateTime 。これは、が実行されたときに、文字列がそれぞれの型に変換されたためです ValidationRuleIn the Validate method override, the Price property is of type Double and the OfferExpires property is of type DateTime because the strings have been converted to their respective types by the time the ValidationRule runs.

public class ValidateDateAndPrice : ValidationRule
    // Ensure that an item over $100 is available for at least 7 days.
    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        BindingGroup bg = value as BindingGroup;

        // Get the source object.
        PurchaseItem item = bg.Items[0] as PurchaseItem;
        object doubleValue;
        object dateTimeValue;

        // Get the proposed values for Price and OfferExpires.
        bool priceResult = bg.TryGetValue(item, "Price", out doubleValue);
        bool dateResult = bg.TryGetValue(item, "OfferExpires", out dateTimeValue);

        if (!priceResult || !dateResult)
            return new ValidationResult(false, "Properties not found");

        double price = (double)doubleValue;
        DateTime offerExpires = (DateTime)dateTimeValue;

        // Check that an item over $100 is available for at least 7 days.
        if (price > 100)
            if (offerExpires < DateTime.Today + new TimeSpan(7, 0, 0, 0))
                return new ValidationResult(false, "Items over $100 must be available for at least 7 days.");

        return ValidationResult.ValidResult;
Public Class ValidateDateAndPrice
    Inherits ValidationRule
    ' Ensure that an item over $100 is available for at least 7 days.
    Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As CultureInfo) As ValidationResult
        Dim bg As BindingGroup = TryCast(value, BindingGroup)

        ' Get the source object.
        Dim item As PurchaseItem = TryCast(bg.Items(0), PurchaseItem)

        Dim doubleValue As Object = Nothing
        Dim dateTimeValue As Object = Nothing

        ' Get the proposed values for Price and OfferExpires.
        Dim priceResult As Boolean = bg.TryGetValue(item, "Price", doubleValue)
        Dim dateResult As Boolean = bg.TryGetValue(item, "OfferExpires", dateTimeValue)

        If (Not priceResult) OrElse (Not dateResult) Then
            Return New ValidationResult(False, "Properties not found")
        End If

        Dim price As Double = CDbl(doubleValue)
        Dim offerExpires As Date = CDate(dateTimeValue)

        ' Check that an item over $100 is available for at least 7 days.
        If price > 100 Then
            If offerExpires < Date.Today + New TimeSpan(7, 0, 0, 0) Then
                Return New ValidationResult(False, "Items over $100 must be available for at least 7 days.")
            End If
        End If

        Return ValidationResult.ValidResult

    End Function
End Class