2010-06-15 6 views
0

디자인 타임에 사용자 지정 IValueConverter을 해제하려면 어떻게합니까? 기본적으로 나는 이것을 쓰고 싶은 :디자인 타임에 사용자 지정 IValueConverter를 해제하려면 어떻게합니까?

Public Class MethodBinder 
    Implements IValueConverter 

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.Convert 
     If [DESIGN_TIME] Then Return Nothing 
     If value IsNot Nothing Then Return CallByName(value, CStr(parameter), CallType.Method) 
     Return Nothing 
    End Function 

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.ConvertBack 
     Throw New NotSupportedException 
    End Function 
End Class 

답변

0

내가 아는 유일한 사람은 UIElement 필요 : 내가 들어오는 (기본값) 값에 특별히 반응이 문제를 해결했다

DesignerProperties.GetIsInDesignMode(UIElement element); 
1

.

예를 들어 런타임에로드 된 라이브러리를 사용하여 수신 오프셋 (확장 방법 사용)을 기준으로 영업일 수를 계산할 경우 라이브러리가로드되지 않았기 때문에 디자인 타임에 실패합니다.

그러나 컨트롤의 기본값은 0, 그래서

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    int offset = 0; 
    if(value is double) 
     offset = (int)(double)value; 

    DateTime dt = offset == 0 
     ? DateTime.Today.Date.AddDays(-offset) 
     : DateTime.Today.Date.AddBusinessDays(-offset) ; 

    return string.Format("{0} ({1})", (offset), dt.ToString("ddd dd-MMM")); 
} 

꽤 아니지만, 그것은 효과적이었다.

관련 문제