CustomControl(dis)中的神秘错误出现在VS 2017中

时间:2018-06-15 20:56:51

标签: c# wpf xaml visual-studio-2017

在处理XAML文件时,我在Visual Studio 2017(版本15.7.3)错误列表窗口中突然收到以下错误消息:

<class>.class.php

首先,我不知道在哪里&#34; Mocks&#34;来自。通过我的解决方案搜索没有给我什么。 第二:错误列表中的错误仅显示在VS中打开XAML文件的时间。如果我关闭它,错误就会消失。 第三:在XAML文件中,我使用名为InputParameter的CustomControl两次。只有第一次使用CustomControl才能给我错误。不是第二个或更晚的。

我说:只有第一个。如果我对第一个进行评论,那么第二个就会被低估。我有另一个XAML文件,同样的事情发生。 请注意:编译顺利,程序正常,文本在正确的位置是白色等。

#FFFFFFFF是白色的颜色编号。 LBForeground是CustomControl中文本颜色的dep-prop。

我觉得代码没有问题,我还没有发布代码。 有没有人见过这种行为?你能告诉我一下吗? 什么是模拟?

1 个答案:

答案 0 :(得分:0)

与在DependencyProperty中将Brushs类型的Colors编号错误有关。 DepProp现在看起来像这样:

public static readonly DependencyProperty TBBackgroundProperty =
      DependencyProperty.Register("TBBackground", typeof(SolidColorBrush), typeof(InputParameter),
          new PropertyMetadata(new SolidColorBrush(Colors.White)));
    public Brush TBBackground
    {
        get
        {
            return (Brush)GetValue(TBBackgroundProperty);
        }
        set
        {
            SetValue(TBBackgroundProperty, value);
        }
    }

在XAML中,必须使用静态资源(即SolidColorBrush)设置TBBackground属性

第一个typeof()不能是这样的字符串:

 WRONGWRONGWRONG:
  public static readonly DependencyProperty TBBackgroundProperty =
      DependencyProperty.Register("TBBackground", typeof(string), typeof(InputParameter),
          new PropertyMetadata("Black"));
    public string TBBackground
    {
        get
        {
            return (string)GetValue(TBBackgroundProperty);
        }
        set
        {
            SetValue(TBBackgroundProperty, value);
        }
    }