2017-05-08 13 views
0

우리는 현재 작업하고있는 문제가 있습니다. 우리는 syncfusion 또는 유사한 WPF 요소에서 DoubleTextBox를 사용하려고합니다. 문제는 다음과 같습니다Syncfusion DoubleTextBox 사용자로부터 입력을 변환하십시오.

사용자는 필드에 345을 입력 할 수 있어야하고 그 유형 4.56 그것은 지금까지 우리가 구현 4.56 을해야하는 경우 그 종류 (35)이 0.35 을해야하는 경우는 자동 3.45 로 수정되었다 아주 잘하는 바인딩을위한 변환기. 그러나 값이 데이터베이스를 통해 300과 같은 10 진수 값으로 입력되면 300.00 컨버터는 점 "."을 찾습니다. -> 그것을 찾지 못해 하나를 두지 않으면 300이 지금 3.00 이것은 잘못된 것입니다. 데이터베이스 값이 312.45이면 제대로 작동합니다. 소수점 이하 자릿수는 모두 0으로 자릅니다./

현재이 변환기는 사용할 수 없습니다.

누구에게 우리의 문제에 대한 아이디어가 있습니까? 지금까지 이것을 수행하는 syncfusion의 WPF 요소가 있습니까?

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    try 
    { 
     if (targetType != typeof(object)) 
     { 
      // Formatierung bei Eingabefeldern 
      if (value != null) 
      { 
       string result = String.Empty; 

       result = value.ToString(); 
       if (!value.ToString().Contains(",")) 
       { 
        decimal _formatted = System.Convert.ToDecimal(value)/100; 

        result = _formatted.ToString("F"); 
       } 
       else if (value.ToString().Contains(",")) 
       { 
        decimal _formatted = System.Convert.ToDecimal(value); 

        result = string.Format("{0:F2}", _formatted); 
       } 

       return result.ToString(); 
      } 
     } 
     else 
     { 
      // Formatierung bei nicht Eingabefeldern 
      if (value == String.Empty) 
      { 
       value = 0; 
      } 

      decimal _formattedcomputed = System.Convert.ToDecimal(value); 
      string resultcomputed = string.Format("{0:F2}", _formattedcomputed); 

      return resultcomputed; 
     } 
    } 
    catch (Exception ex) 
    { 

    } 

    return null; 
} 
+0

변환기 및 viewmodel 속성에 대한 코드를 공유하십시오. viewmodel 속성이 문자열 인 것 같습니다. –

+0

내 viewmodelproperty는 10 진수입니다. –

+0

ConvertBack 메서드가 있습니까? –

답변

0

이 나를 위해 제대로 작동 :

는 변환기입니다.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    try 
    { 
     // Formatierung bei Eingabefeldern 
     if (value != null) 
     { 
      string inputStr = value.ToString(); 
      decimal inputDecimal = System.Convert.ToDecimal(value); 

      if (inputStr.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)) 
      { 
       return inputDecimal.ToString("F2"); 
      } 
      else 
      { 
       inputDecimal /= 100; 

       return inputDecimal.ToString("F"); 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     System.Diagnostics.Trace.WriteLine(
      String.Format("Error converting value {0}: {1}", value, ex.Message)); 
    } 

    return null; 
} 

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    return value; 
} 
+0

고맙습니다. :) 그것은 우리 솔루션에 완벽하게 작동합니다. –