XAMLウィンドウにTextBoxがあり、このTextBoxにErrorTemplateがあります。ErrorTemplateが表示されると、XAML GridRowは自動的に縮尺されません。
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はHeight = "Auto"のGridRowの内部にあります。行はテキストボックスに基づいてスケールされますが、ErrorTemplateが表示されたときに下部に余分なTextBoxが表示されると、GridRowは新しいTextBoxを含むように拡大されず、新しいTextBoxはその下の要素と重なります。
どうすればこの問題を解決できますか?
何に追加しますか?コントロールテンプレート? – user884248
周り –