xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.9k stars 878 forks source link

MaterialTextField SelectAll Failing #1719

Open ZionGates opened 2 years ago

ZionGates commented 2 years ago

Greetings, I'm using the MaterialTextField and the SelectAll method and the SelectionLength mthod both fail to select the text in the control. I'm attempting to Select the text when the control gets focus.

Please advise.

XceedBoucherS commented 2 years ago

Hi,

You could always try to use your own MaterialTextField and call a SelectAll() on the MaterialTextBox's TextBox when the MaterialTextBox gets the focus: public class MyMaterialTextField : MaterialTextField { public MyMaterialTextField() { this.GotFocus += this.MyMaterialTextField_GotFocus; }

private void MyMaterialTextField_GotFocus( object sender, System.Windows.RoutedEventArgs e )
{
  this.Dispatcher.BeginInvoke( DispatcherPriority.Input, new Action( () =>
  {
    var textBox = e.OriginalSource as TextBox;
    if( textBox != null )
    {
      textBox.SelectAll();
    }
  }
     ) );

}

}

ZionGates commented 2 years ago

Thanks, that worked, however that seems like a complex workaround.

XceedBoucherS commented 2 years ago

Yes, I know.

Even if the MaterialTextField derives from TextBox, it has a completely redefined template. So the MaterialTextField.SelectAll() method(from TextBox) won't work. We could internally call the SelectAll() method on the inner TextBox from the Template, but when ? You want it when the control gets focus, but someone else could want it for any other reasons. So the workaround here is for you to call it on the inner TextBox when you want it.