2014-07-21 1 views
0

저는 WatermarkTextBox 컨트롤에 WPF 툴킷을 사용하고 있습니다.인라인을 WatermarkTextBox로 다시 변환

내 응용 프로그램은 사용자가 입력 할 텍스트 문자열과 자리 표시자를 동적으로 연결하여 공백을 채 웁니다.

foreach(var e in elements) 
{ 
    if (isText) 
    { 
     LetterText.Inlines.Add(new Run 
     { 
      Text = e, 
      BaselineAlignment = BaselineAlignment.Center 
     }); 
    } 
    else 
    { 
     LetterText.Inlines.Add(new WatermarkTextBox 
     { 
      Watermark = e 
     }); 
    } 

    isText = !isText; 
} 

이 아주 잘 작동하지만 텍스트를 재 조립 할 때 내 문제가 발생

이것은 다른 절없이 ('WatermarkTextBox에 인라인 변환 할 수 없습니다'와 컴파일 타임에 실패
foreach(var inline in LetterText.Inlines) 
{ 
    if (inline.GetType() == typeof(Run)) 
    { 
     sb.Append(((Run)inline).Text); 
    } 
    else if (inline.GetType() == typeof(WatermarkTextBox)) 
    { 
     var wtb = inline as WatermarkTextBox; 
     sb.Append(wtb.Text); 
    } 
} 

, Inline에서 Run으로 변환하면 문제가 없습니다.

WatermarkTextBox에서 텍스트를 가져 오는 방법은 무엇입니까?

  if (inline.GetType() == typeof(Run)) 
      { 
       sb.Append(((Run)inline).Text); 
      } 
      else if (inline.GetType() == typeof(InlineUIContainer)) 
      { 
       var container = inline as InlineUIContainer; 
       var wtb = container.Child as WatermarkTextBox; 

       if (wtb !=null) 
        sb.Append(wtb.Text); 
      } 

InlineUIContainer도 암시 Run 요소

생성되지 않는 이유를 모르겠어요 :

답변

0

는 속임수를 썼는지
관련 문제