Skip to content

Commit

Permalink
paste with right-click
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Jan 11, 2021
1 parent bcd157f commit 75f5a52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/View.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
FontSize="14"
ContextMenu="{x:Null}"
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
PreviewKeyDown="SearchTextBox_PreviewKeyDown" >
PreviewKeyDown="SearchTextBox_PreviewKeyDown"
PreviewMouseRightButtonDown="SearchTextBox_PreviewMouseRightButtonDown" PreviewMouseRightButtonUp="SearchTextBox_PreviewMouseRightButtonUp" >
</TextBox>

<DataGrid Name="DG"
Expand Down
11 changes: 11 additions & 0 deletions src/View.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e)

IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// WM_SYSKEYDOWN
if (msg == 0x104 && (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)))
{
Application.Current.Dispatcher.InvokeAsync(() => {
Expand Down Expand Up @@ -180,5 +181,15 @@ void Window_Loaded(object sender, RoutedEventArgs e)
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
source.AddHook(new HwndSourceHook(WndProc));
}

void SearchTextBox_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
SearchTextBox.Text = Clipboard.GetText();
}

void SearchTextBox_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
SearchTextBox.SelectionStart = SearchTextBox.Text.Length;
}
}
}

0 comments on commit 75f5a52

Please sign in to comment.