UFO ET IT

기본값 유형이 속성 유형과 일치하지 않습니다.

ufoet 2020. 11. 7. 18:14
반응형

기본값 유형이 속성 유형과 일치하지 않습니다.


이 수업이 있습니다

public class Tooth
{
    public string Id {get;set;}
}

그리고이 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)); 

}

내 문제는 Add Tooth 종속성 속성 후입니다 .이 오류가 발생합니다.

기본값 유형이 속성 유형과 일치하지 않습니다.

이 오류는 정확히 무엇을 의미합니까? 이것을 설정하는 현재 방법은 무엇입니까DP


Default value에 대한 DP당신의 유형과 일치하지 않습니다.

변화

public static readonly DependencyProperty ToothProperty =
        DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI),
                                         new PropertyMetadata(0));

...에

public static readonly DependencyProperty ToothProperty =
        DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI),
                                      new PropertyMetadata(default(Tooth)));

또는 DP에 대한 기본값 설정을 생략하십시오.

public static readonly DependencyProperty ToothProperty =
        DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI));

나는 질문의 제목을 위해 여기에 왔지만 내 유형은 10 진수 기본값이었고이 0.0M https://msdn.microsoft.com/en-us/library/83fhsxwc.aspx로 해결했습니다.

참고 URL : https://stackoverflow.com/questions/20398751/the-default-value-type-does-not-match-the-type-of-the-property

반응형