我的一个 XAML 文件在 XAML 设计器中显示了一个奇怪的行为(但不是在运行时):
public class MyDesignTimeViewModel
{
public MyDesignTimeViewModel()
{
MyText = "abc";
MyInt = 5;
}
public string MyText { get { ... } }
public int MyInt { get { ... } }
}
然后在 XAML 中:
<UserControl xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
...
d:DataContext="{d:DesignInstance vm:MyDesignTimeViewModel}"
>
<TextBlock Text="{Binding MyText}" />
<TextBlock Text="{Binding MyInt}" />
</UserControl>
在 XAML 设计器中,两个 TextBlock 实例显示以下内容:
MyText
0
XAML 设计器显示字符串属性的属性名称,对于 int 属性,它显示 0。
错误窗口中没有错误。此外,它似乎实际上读取了属性,因为如果我将绑定更改为不存在的属性名称,内容就会消失。
我重新启动了 Visual Studio 和我的电脑并删除了该.suo
文件。
对这种行为有什么解释吗?