具有自定义控件的DataGrid CellEditingTemplate不会在DataGrid级别上触发验证错误

时间:2016-11-04 11:48:28

标签: c# wpf validation datagrid

我使用的是DataGrid,我创建了一个名为Time_Edit的自定义控件。此控件是一个带有两个TextBox控件的复杂控件。

 <DataTemplate x:Key="Time_Edit">
     <local:TimeView DataContext="{Binding TimeViewModel}"/>
 </DataTemplate>

TimeViewModel是主视图模型的属性。

我添加了DataGrid.RowValidationErrorTemplate

 <DataGrid.RowValidationErrorTemplate>
    <ControlTemplate>
        <Viewbox>
            <Grid Margin="0,-2,0,-2"
                ToolTip="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, Path=(Validation.Errors)[0].ErrorContent}">
                <Ellipse StrokeThickness="0" Fill="Red" Width="{TemplateBinding FontSize}"
                    Height="{TemplateBinding FontSize}"/>
                <TextBlock Text="!" FontSize="{TemplateBinding FontSize}" 
                    FontWeight="Bold" Foreground="White" 
                    HorizontalAlignment="Center"  />
            </Grid>
        </Viewbox>
    </ControlTemplate>
</DataGrid.RowValidationErrorTemplate>

以下是截图:

Screenshot

绑定工作正常。验证在TextBox控制级别执行,但不在DataGridRow级别执行。有人能帮助我吗?

0 个答案:

没有答案
相关问题