티스토리 뷰

전공/WPF 삽질들..

system.windows.data error: 23

무한공백 2014. 3. 21. 15:07


아래처럼 xml에서 Image를 바인딩을 통해 로딩할 때,

ImagePath가 null 또는 "" 일경우 system.windows.data error: 23 Cannot convert '' from type '' to type ... 와 같은 에러가 난다.

이럴 경우 바인딩된 변수를 아래와 같이 해결하면 에러가 나지 않는다.
 private string _imagePath = string.Empty;
    public object ImagePath 
    {
        get
        {
            if (string.IsNullOrEmpty(_imagePath))
                return DependencyProperty.UnsetValue;

            return _imagePath;
        }
        set
        {
            if (!(value is string)) 
                return;

            _imagePath = value.ToString();
            OnPropertyChanged("ImagePath");
        }
    }


'전공 > WPF 삽질들..' 카테고리의 다른 글

WPF 디자이너 오류 중 하나  (0) 2015.02.27
Disable Backspace, Navigate application  (0) 2014.03.21
ListBox Item Context 메뉴 호출  (0) 2014.03.21
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함