Run Event TextBox c # WPF

0

I have a Textbox and need to press the right button and click paste, it checks, tried several methods like

TxtTexto.PreviewMouseLeftButtonDown+= new MouseButtonEventHandler(OnMouseClick);
TxtTexto.MouseUp += new MouseButtonEventHandler(OnMouseClick);
TxtTexto.PreviewMouseDown += new MouseButtonEventHandler(OnMouseClick);
TxtTexto.MouseDown += new MouseButtonEventHandler(OnMouseClick);

Among other codes, is it possible to capitalize on this event?

    
asked by anonymous 05.10.2018 / 22:24

1 answer

1

Try something like this.

public Window1()
{
    InitializeComponent();

    // "tb" é o seu TextBox
    DataObject.AddPastingHandler(tb, OnPaste);
}

private void OnPaste(object sender, DataObjectPastingEventArgs e)
{
    //faça suas verificações aqui use o 'e' para obter os dados presente no past.
    var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
    if (!isText) return;

    var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;

}
  

References    link

    
05.10.2018 / 22:42