2011-06-07 7 views
2

私は単純なDataGridTextColumn列を持つSL4にDataGridを持っています。セルエントリのすべてのSilverlight DataGridセルテキストを選択します。

私は、編集可能なテキストボックスにセルが変更されるとすぐに、DataGridCellのすべてのテキストを選択するためにさまざまな方法を試しました。

以下のコードは私の最後の試みでした。

デバッグでTextBoxを検査すると、SelectedTextプロパティがTextプロパティと等しいことが示されます。したがって、問題はTextBoxではありません。それは後でテキストの選択を解除しているようです。

public void PreparingCellForEdit(DataGridPreparingCellForEditEventArgs e) 
    { 
     var textBox = e.EditingElement as TextBox; 
     if (textBox != null && !string.IsNullOrEmpty(textBox.Text)) 
     { 
      textBox.GotFocus += (s, e2) => 
       { 
        { 
         textBox.SelectAll(); 
        } 
       }; 
     } 
    } 

テキストを選択したままにして、選択したテキストのTextBoxをユーザーに表示する方法はありますか?

P.S. PreparingCellForEditイベントを添付するためにCliburn.Microを使用しています。

答えて

0

GotFocusイベントにアタッチした後、フォーカスを強制的にTextBoxにすることです。

public void PreparingCellForEdit(DataGridPreparingCellForEditEventArgs e) 
    { 
     var textBox = e.EditingElement as TextBox; 
     if (textBox != null) 
     { 
      textBox.GotFocus += (s, e2) => textBox.SelectAll(); 
      textBox.Focus(); 
     } 
    } 
2

何私のためにうまく機能することは以下の通りです:

public void PreparingCellForEdit(DataGridPreparingCellForEditEventArgs e) 
{ 
    var textBox = e.EditingElement as TextBox; 
    if (textBox != null) 
    { 
     textBox.Dispatcher.BeginInvoke(() => textBox.SelectAll()); 
    } 
} 
このよう

関連する問題