gpt4 book ai didi

c# - Mahapps 数据网格验证

转载 作者:行者123 更新时间:2023-11-30 18:24:47 26 4
gpt4 key购买 nike

我正在使用 MahApps在 WPF 项目上,我正在尝试使用 MahApps 的内置样式对 DataGrid 控件提供一些验证, 但我定义的验证样式没有显示。

DataGrid 是:

<DataGrid BorderThickness="2" Margin="0,10,0,93" AutoGenerateColumns="False" FontSize="18"
SelectionUnit="FullRow" SelectionMode="Single"
ItemsSource="{Binding DocumentLines, Mode=TwoWay}" CanUserAddRows="False" CanUserDeleteRows="False">

<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding ProductName}" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Header="Code" Binding="{Binding ProductCode}" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Header="Quantity" Binding="{Binding Quantity, ValidatesOnExceptions=True}" Width="*"/>
<DataGridTemplateColumn Header="VATPercentage" Width="*" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding VATPercentage, StringFormat=N}" TextAlignment="Right" Margin="0,0,5,0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>

<DataGrid.RowValidationRules>
<val:Validation ValidationStep="UpdatedValue"/>
</DataGrid.RowValidationRules>

<DataGrid.RowValidationErrorTemplate>
<ControlTemplate>
<Grid Margin="0,-2,0,-2"
ToolTip="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGridRow},
Path=(Validation.Errors)[0].ErrorContent}">
<Path Height="20" Width="20" Stretch="Uniform" Fill="Red" Data="F1 M 12.2495,36.8804L 36.8804,12.2496C 37.4987,11.6312 38.5012,11.6312 39.1196,12.2496L 63.7504,36.8804C 64.3688,37.4988 64.3688,38.5013 63.7504,39.1196L 39.1196,63.7505C 38.5013,64.3688 37.4987,64.3688 36.8804,63.7505L 12.2495,39.1196C 11.6312,38.5013 11.6312,37.4988 12.2495,36.8804 Z M 38,45.125C 36.0325,45.125 34.4375,46.72 34.4375,48.6875C 34.4375,50.655 36.0325,52.25 38,52.25C 39.9675,52.25 41.5625,50.655 41.5625,48.6875C 41.5625,46.72 39.9675,45.125 38,45.125 Z M 34.4375,23.75L 35.625,42.75L 40.375,42.75L 41.5625,23.75L 34.4375,23.75 Z"/>
</Grid>
</ControlTemplate>
</DataGrid.RowValidationErrorTemplate>

</DataGrid>

ValidationRule 是:

public class Validation : ValidationRule
{
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
Line line = (value as BindingGroup).Items[0] as Line;

if (line.Quantity <= 0)
return new ValidationResult(false, "Erro");

return ValidationResult.ValidResult;
}
}

我在 Onedrive sample 中发布了一个小的工作示例验证样式仅在 App.xaml 上未引用 MahApps 样式时出现。

谁能帮我解决这个问题?

最佳答案

显然,这已在 Mahapps.Metro 的 1.2 版中得到解决,请参阅 here了解更多详情:

关于c# - Mahapps 数据网格验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30851876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com