我在我的wpf应用程序中添加了一些错误管理。我有两个问题:
我无法将红色边框仅适合文本框或combox。如果错误消息文本大于字段,则边框大于字段。
我可以在我的数据网格中的最后一行显示消息。该消息由datagrid
我想告诉你图像,但我不能发布一个,没有足够的声誉点:S
这是我的代码:
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource DefaultComboBox}" >
<Setter Property="Validation.ErrorTemplate" Value="{DynamicResource ErrorSeverityValidation}" />
</Style>
<ControlTemplate x:Key="ErrorSeverityValidation">
<ControlTemplate.Resources>
<Style x:Key="TextblockErrorTooltip" TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Margin" Value="10 0 10 0" />
</Style>
</ControlTemplate.Resources>
<DockPanel ZIndex="99" Dock="Bottom">
<Grid DockPanel.Dock="Bottom">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Path Grid.Row="1" Margin="15 0 0 0" Width="20" Height="10" HorizontalAlignment="Left" VerticalAlignment="Top" Data="M0,10 L10,0 20,10Z"
Stroke="{StaticResource DangerBackgroundBrush}" DockPanel.Dock="Bottom" Fill="{StaticResource DangerBackgroundBrush}" Stretch="None" />
<Border Grid.Row="2" Height="Auto"
Margin="0,0,0,5"
CornerRadius="3" DockPanel.Dock="Bottom"
>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="{StaticResource DangerBackgroundBrush}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ErrorContent.Severity}" Value="{x:Static local:Severity.Warning}">
<Setter Property="Background" Value="{StaticResource WarningBackgroundBrush}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Style="{StaticResource TextblockErrorTooltip}"
Text="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent.ValidationMessage}" />
</Border>
<AdornedElementPlaceholder Grid.Row="0" Name="customAdorner">
<Border BorderBrush="{StaticResource DangerBackgroundBrush}" BorderThickness="1.3" DockPanel.Dock="Left" />
</AdornedElementPlaceholder>
</Grid>
</DockPanel>
</ControlTemplate>
如果您需要查看我的数据网格代码,请告诉我哪个部分:)
更新
好的,在我的研究中,我认为我的问题更多的是datagridcell不会调整大小以适应内容。我做了很多研究,但我找不到办法解决问题。
<DataGridTemplateColumn Width="80">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Width="80" TextWrapping="Wrap"
Text="{Binding Source={StaticResource UIStrings}, Mode=OneWay, Path=.[AnimalEventResources.Wean_qtyWeaned],FallbackValue=@WeanNumber}" />
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<controls:CustomIntegerBox GotFocus="OnGotFocus" HorizontalAlignment="Center" Width="70"
Text="{Binding WeanNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True,NotifyOnValidationError=True}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
我尝试将高度设置为celltemplate,我尝试将内容放入带有包装的文本框中......但没有成功!