2014-01-15 59 views

回答

0

您可以擴展AutoCompleteBox類,或直接在代碼中直接獲取TextBox並調用Select方法。

AutoCompleteBox默認模板TextBox被命名爲「文本」,這樣你就可以調用yourAutoCompleteBox.Template.FindName("Text", yourAutoCompleteBox)得到TextBox,或創建一個派生類是這樣的:

public class AutoCompleteBoxEx : AutoCompleteBox 
{ 
    private TextBox _textBox; 

    public override void OnApplyTemplate() 
    { 
     base.OnApplyTemplate(); 
     if (Template == null) return; 
     _textBox = Template.FindName("Text", this) as TextBox; 
    } 

    public void Select(int start, int length) 
    { 
     if (_textBox == null) return; 
     _textBox.Select(start, length); 
    } 
} 
+0

謝謝,萊昂!我會試試這個。 – enlilbinny

相關問題