2

WPF アプリケーションでは、ExceptionValidationRule を使用していくつかの TextBox でバインドを使用します。正しいデータ入力が得られるまで、ApplicationException が残っているコントロールにとどまることができるようにしたいと思います。可能性はありますか?

これが私のコードです:

 public string strEvtType
    {
        get { return m_strEvtType; }
        set {
                m_strEvtType = value;
                if (m_objEvtCode.ReadEvtTypebyType(m_strEvtType) != 0)
                {
                    throw new ApplicationException("Error ! : " + m_strEvtType.Trim() + " don't exist");
                }
                FirePropertyChangedEvent("strEvtType");
                FirePropertyChangedEvent("m_objEvtCode.strDes");

            }

私のxaml:

<TextBox Name="TextBox_TypeEvenement" Grid.Column="1" VerticalAlignment="Center" Height="20" LostFocus="TextBox_TypeEvenement_LostFocus">
  <TextBox.Text>
    <Binding Path="strEvtType">
        <Binding.ValidationRules>
            <ExceptionValidationRule />
        </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>

マイ テンプレート

<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
    <Setter.Value>
        <ControlTemplate>
            <DockPanel  LastChildFill="False">
                <TextBlock DockPanel.Dock="Right"
                Foreground="red"
                FontSize="9pt"
                Text="{Binding ElementName=MyAdorner,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                </TextBlock>
                <Border BorderBrush="Red" BorderThickness="1">
                    <AdornedElementPlaceholder Name="MyAdorner" />
                </Border>
            </DockPanel>
        </ControlTemplate>
    </Setter.Value>
</Setter>

どうもありがとう :)

よろしくお願いします、

ニクセウス

4

0 に答える 0