【问题标题】:Define TextBox Validation.Error Event at root (UserControl)在根 (UserControl) 定义 TextBox Validation.Error 事件
【发布时间】:2012-09-03 16:56:30
【问题描述】:
我创建了一个用户控件MyTextBox : System.Windows.Controls.TextBox。我在数据绑定中添加了自定义验证规则,还在 XAML 中定义了Validation.Error 事件。
我想将Validation.Error 事件移至根目录 (MyTextBox),以便我可以通用地处理它。我无法在 Usercontrol 中实现这种方法。
谁能帮忙?
【问题讨论】:
标签:
c#
wpf
validation
data-binding
【解决方案1】:
我得到了我的问题答案。这是加载事件的实现
//Check whether Designer mode is open. If not then set Custom binding
if ((bool)(DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue) == false)
{
SetBinding();
}