0

検証ルールを textBox に追加したかったのですが、問題は、次のコードを実行すると、次のエラー メッセージが表示されることです。

タイプ 'myValidations' の値は、タイプ 'Collection`1' のコレクションまたはディクショナリに追加できません。

クラス myValidations ロールがアクティブです。

何が問題になる可能性がありますか?

    <TextBox x:Name="Name" Grid.Column="4" Margin="0,50,0,0"  Grid.Row="2" Style="{StaticResource tooltipError}">
        <Binding ElementName="textBlock" Path="Text">
                <Binding.ValidationRules>
                    <viewModel:MyValidationsRules/>
                </Binding.ValidationRules>
            </Binding>
    </TextBox>

テキスト ボックスは、次のスタイルから継承されます。

        <Style TargetType="TextBox">
            <Setter Property="AcceptsReturn" Value="True"/>
            <Setter Property="AllowDrop" Value="True"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="Height" Value="44"/>
            <Setter Property="Width" Value="199"/>
            <Setter Property="TextWrapping" Value="Wrap"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <EventSetter Event="PreviewDragEnter"
                   Handler="DropText_PreviewDragEnter"/>
            <EventSetter Event="PreviewDrop"
                   Handler="DropText_PreviewDrop"/>
            <EventSetter Event="PreviewDragOver"

        </Style>
4

2 に答える 2

1

問題についてはよくわかりませんが<TextBox.Text>、コード内のタグを見逃していると思います。

<TextBox x:Name="Name" Grid.Column="4" Margin="0,50,0,0"  Grid.Row="2" Style="{StaticResource tooltipError}">
<TextBox.Text>
        <Binding ElementName="textBlock" Path="Text">
                <Binding.ValidationRules>
                    <viewModel:MyValidationsRules ValidatesOnTargetUpdated="True"/>
                </Binding.ValidationRules>
            </Binding>
</TextBox.Text>
    </TextBox>
于 2014-01-28T14:56:42.153 に答える