2012-01-02 3 views
1

Silverlight의 GetCharacterIndexFromPoint에 해당하는 항목이 있습니까? 또는 다른 방법으로 내 개체가 드롭 된 (끌어서 놓기 방법에서) 위치를 결정할 수 있습니까?Silverlight의 GetCharacterIndexFromPoint

답변

1

Silverlight는 GetRectFromCharacterIndex()을 지원하기 때문에 GetCharacterIndexFromPoint()을 다시 구현할 수 있습니다 (그러나 느리게 진행될 것이고 불행히도 snapToText 인수를 지원하지 않음). (테스트되지 않은) 같은

뭔가 :

public static int GetCharacterIndexFromPoint(this TextBox textBox, Point point) 
{ 
    try { 
     return Enumerable.Range(0, textBox.Text.Length).First(
      index => { 
       Rectangle rect = textBox.GetRectFromCharacterIndex(index, false); 
       rect.Union(textBox.GetRectFromCharacterIndex(index, true)); 
       return rect.Contains(point); 
      }); 
    } catch (InvalidOperationException) { 
     // No character lies at specified point. 
     return -1; 
    } 
} 
+1

을 사용하는 것입니다 "방법 또는 작업이 구현되지 않습니다." 예외. 아마도 내가 어떻게해야합니까? – Zozo

+0

Silverlight 3 이하를 사용하고있는 것 같습니다. 이 메서드는 Silverlight 4 이상에서만 지원됩니다. 어쩌면 업그레이드 할 수 있을까요? –

+0

Silverlight 4를 사용하고 있습니다 – Zozo