Setting Validation error template from code in WPF

前端 未结 4 1285
醉话见心
醉话见心 2021-02-13 22:40

I have a TextBox in my WPF app. I have defined a ControlTemplate for validation error as follows:


    

        
4条回答
  •  长情又很酷
    2021-02-13 22:53

    For your first question. You can set the ErrorTemplate from code behind like.

        public MainWindow()
        {
            InitializeComponent();
    
            var template = this.FindResource("validationTemplate") as ControlTemplate;
            Validation.SetErrorTemplate(this.textBox1, template);
         }
    


    Edit: For your second question. Please refer the following sample. sites.google.com/site/html5tutorials/ValidationErrorText.zip

提交回复
热议问题