gpt4 book ai didi

wpf - 在WPF中,如何在TextBox中显示验证错误,如下图所示?

转载 作者:行者123 更新时间:2023-12-02 05:08:09 25 4
gpt4 key购买 nike

我有一个绑定(bind)到某些属性的文本框。我已经实现了 IDataErrorInfo 来执行验证。最近,我在网络中看到一些控件显示错误,例如红色三角形。我已附上以下示例:

enter image description here

我知道我必须编写错误模板来在发生错误时显示它。当用户将鼠标悬停在红色三角形上时,它将在工具提示中显示错误消息。如何显示像我上传的错误文本框。如何获取错误模板中的红色三角形?

最佳答案

这是一个如下所示的示例

enter image description here

像这样使用

<TextBox Validation.ErrorTemplate="{StaticResource topRightCornerErrorTemplate}"
.../>

错误模板

<ControlTemplate x:Key="topRightCornerErrorTemplate">
<Grid>
<Polygon Points="40,20 40,0 0,0"
Stroke="Black"
StrokeThickness="1"
Fill="Red"
HorizontalAlignment="Right"
VerticalAlignment="Top"
ToolTip="{Binding ElementName=adorner,
Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/>
<AdornedElementPlaceholder x:Name="adorner"/>
</Grid>
</ControlTemplate>

关于wpf - 在WPF中,如何在TextBox中显示验证错误,如下图所示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7147894/

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