Jua*_*mez 71 c# wpf wpf-controls
我有这门课
public class Tooth
{
public string Id {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
而这个custrom控制
public partial class ToothUI : UserControl
{
public ToothUI()
{
InitializeComponent();
}
public Tooth Tooth
{
get { return (Tooth)GetValue(ToothProperty); }
set
{
SetValue(ToothProperty, value);
NombrePieza.Text = value.Id.Replace("_",String.Empty);
}
}
public static readonly DependencyProperty ToothProperty =
DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI), new PropertyMetadata(0));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在Add Tooth依赖项属性之后,发生此错误
默认值类型与属性的类型不匹配
这个错误究竟是什么意思?目前设置此方法的方式是什么DP
Roh*_*ats 132
Default valuefor DP与您的类型不符.
更改
public static readonly DependencyProperty ToothProperty =
DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI),
new PropertyMetadata(0));
Run Code Online (Sandbox Code Playgroud)
至
public static readonly DependencyProperty ToothProperty =
DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI),
new PropertyMetadata(default(Tooth)));
Run Code Online (Sandbox Code Playgroud)
或者只是省略DP的默认值设置:
public static readonly DependencyProperty ToothProperty =
DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21699 次 |
| 最近记录: |