0

TextBox を含む XAML ウィンドウがあり、この TextBox には ErrorTemplate があります。

ErrorTemplate を以下に示します。ご覧のとおり、AdornedElementPlaceholder があり、その後にテキスト フィールドが ErrorContent にバインドされたテキスト ボックスが続きます。

<ControlTemplate x:Key="ValidationErrorTemplateTextBlock" TargetType="{x:Type Control}">
    <Border BorderBrush="Red" BorderThickness="1">
        <StackPanel Orientation="Vertical">
            <AdornedElementPlaceholder Name="AdornedElementPlaceholder" />
            <TextBlock Text="{Binding ElementName=AdornedElementPlaceholder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" 
                    FontSize="10"
                    Background="Red"
                    Foreground="White"
                    Padding="2" />
        </StackPanel>
    </Border>
</ControlTemplate>

<TextBox IsEnabled="{Binding SendMessage}"
                    Text="{Binding AutoMessageSubject, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                    Style="{StaticResource StyleBase}"
                    Validation.ErrorTemplate="{StaticResource ValidationErrorTemplateTextBlock}"
                    HorizontalAlignment="Stretch"
                    Grid.Row="3"
                    Grid.Column="1"
                    Grid.ColumnSpan="2" />

TextBox が GridRow 内にあり、Height="Auto" であることを除いて、これは正常に機能します。行はテキストボックスに基づいて自動的にスケーリングされますが、ErrorTemplate が表示され、下部に追加の TextBox が表示されると、GridRow は新しい TextBox を含むように拡大されず、新しい TextBox はその下の要素に重なります。

どうすればこれを解決できますか?

4

2 に答える 2

0

行/列の定義を追加してみてください:

<Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
于 2016-11-04T20:56:03.230 に答える