简体   繁体   中英

XAML can't find namespace for validating

(Bear with me, I am still learning WPF and especially MVVM!)

I wrote a Validation Rule, and wrote the style and everything in the XML. I am getting one small problem that I cannot understand and its that the XAML says the namespace doesn't exist. At the XAML header I added this:

xmlns:validators="clr-namespace:New_ComplaintManager.ViewModels"

And in my textbox I have this:

validators:RequiredFields ErrorMessage="username is required." />

Yet XAML says:

The tag 'RequiredFields' does not exist in XML namespace 
'clr-namespace:New_ComplaintManager.ViewModels'.

But the ViewModel contains this:

namespace New_ComplaintManager.ViewModels
{
class RequiredField
{
    public class RequiredFields : ValidationRule

So I am stuck. I am missing something incredibly obvious or I messed up somewhere. I even read this guide: XAML MSDN Guide to no avail. Any help would be fantastic. This has been a good learning experience though!

Please make changes as below

namespace New_ComplaintManager.ViewModels
{
  public class RequiredFields : ValidationRule
  {

  }

}

Please remove Below lines

class RequiredField

Need of removing above class because it is not defined publicly and your RequiredFields class will not be known to outside.

正如Ashok Rathold已回答的那样-我加2美分:尝试像中使用完整声明

xmlns:validators="clr-namespace:clr-namespace:New_ComplaintManager.ViewModels;assembly=your_assembly"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM