I'm developing a simple Windows Phone 8 app and I have the keyboard show up correctly using the Url InputScope. At the bottom right corner of the soft keyboard (SIP) a right arrow is displayed.
How do I detect that the user clicks that button?
I've tried the KeyUp-event, but the Key class is not defined so I can't compare e.Key with Key.ENTER - and I also have a feeling that it isn't correct to check the key code, semantically speaking. I'd rather find some "onSubmit" event like in HTML.
I got it working by first adding "using System.Windows.Input;" to the top of my .cs file. After that the Key class became available.
XAML:
<TextBox KeyUp="txtUrl_KeyUp" x:Name="txtUrl" InputScope="Url" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" TextWrapping="Wrap" VerticalScrollBarVisibility="Disabled" ManipulationCompleted="txtUrl_ManipulationCompleted" Margin="0,127,0,0" Grid.RowSpan="2" />
C#:
private void txtUrl_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key.Equals(Key.Enter)) {
navigateTo(txtUrl.Text);
webBrowser.focus(); // Hides the input box
}
}
Related
On keyboard button name as BackSpace do not work as backspace for multiple textBoxes.
for single textbox i write this code and successfully .
textbox.text = textbox.Text.Remove(textbox.Textlength-1,1);
but not work for multiple textboxes.
Edit Note that this is an WPF answer but the question is about winforms. I'll leave the answer for now in case someone looks for the same thing with WPF.
You can use the FocusManager.IsFocusScope property:
<StackPanel>
<StackPanel x:Name="tbElements" FocusManager.IsFocusScope="True">
<TextBox x:Name="tb1" Margin="3" VerticalAlignment="Top"/>
<TextBox x:Name="tb2" Margin="3" VerticalAlignment="Top"/>
</StackPanel>
<Button Content="Test" Margin="3" Height="26" Click="Button_Click"/>
</StackPanel>
Then the textboxes are managed in a separate logical focus scope
private void Button_Click(object sender, RoutedEventArgs e)
{
var test1 = FocusManager.GetFocusedElement(this);
var test2 = FocusManager.GetFocusedElement(tbElements);
}
The result will be, that test1 references the clicked button, because it has the current focus, but test2 references the last focused textbox, because it has the local focus within its separate logical focus scope.
An alternative would be to set the Button property Focusable to False, so if a textbox has the focus when the button is clicked, the focus stays within the textbox. This prevents keyboard navigation to the button but since the button is part of the screen keyboard, this may be acceptable or even desired behavior.
I am pretty sure that OP does not want to perform backspaces on multiple textboxes, rather wants Backspace button to affect textbox currently focused, so:
To emulate a keyboard stroke use SendKeys.Send(string keys) instead of current implementation. This will perform BACKSPACE on control which has focus:
private void backspace_Click(object sender, EventArgs e)
{
//{BACKSPACE}, {BS}, or {BKSP}
SendKeys.Send("{BACKSPACE}");
}
I am building a small UWP app in C#, to scan EAN barcodes and assigning descriptions to it.
The default action when I click on my textboxes is to start speech recognition. And I want the textbox to go into manual editing mode, when I rightclick it (long tap on touch-devices).
Therefore I'd like to remove the default context-menu for my TextBox control.
I know how to do this in Windows Forms applications (just add an empty TextBox.ContextMenu with visibility=Collapsed).
Can somebody here help me please, and tell me how to remove the default "Paste" context menu (or "flyout") entry from my textboxes?
Is this even possible?
Screenshot: UWP default Textbox context menu
You can to disable context menu of TextBox, ContextMenuOpening event will help you. Below is the whole code.
XAML:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBox x:Name="textBox" Text="test" Height="80" Width="100" ContextMenuOpening="TextBox_ContextMenuOpening" />
</Grid>
C#:
private void TextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
e.Handled = true;
}
The Problem
Lync has some hotkeys/shortcut keys for changing the tabs in the ContactList control. These hotkeys are 'g', 's' and 'r'. When I press any of these keys whilst having a HTML input control focused inside a WebBrowser on any web page, the key presses are going to the ContactList control instead of the WebBrowser control.
The key presses aren't stolen when typing into a control outside the browser, such as a WPF TextBox control.
Steps to reproduce the problem
Have Microsoft Lync 2013 installed
Download and install the Microsoft Lync 2013 client sdk from http://www.microsoft.com/en-au/download/details.aspx?id=36824
Create a .net 4.0 wpf application. Drag and drop a ContactList control into MainWindow so it automatically sets up the references and namespaces
Paste the following code inside the Window element in MainWindow.xaml
<Window...
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:ContactList Name="contactList1" Grid.Column="0" />
<WebBrowser Grid.Column="1" Source="http://www.google.com" />
</Grid>
Press the 'r', 'g' or 's' key into the google search box and notice how the key presses go to the lync control instead of the search box. Any other keys work like normal.
Things I've tried
I've tried to stop the key event bubbling to the ContactList control. However i haven't had much success with this.
disable event-bubbling c# wpf
WPF prevent event bubbling outside of a control
Found the answer here: AccessKey Pressed Event Raised when pressing access key without ALT
This behaviour occurs because WPF doesn't require alt to be held down in order for AccessKeys to work. Where as WinForms does.
In this case pressing 'g', 's', or 'r' from within the WebBrowser focuses the ClientControl, but I only want this to happen when holding down alt. I don't know why this problem only seems to happen with WebBrowser though.
From the msdn link:
We have defined an access key on a label, which gives focus to a
textbox.
We have a second readonly textbox on the same user control.
When clicking inside the readonly textbox and pressing the access key
without ALT (e.g. L instead of ALT + L) the focus change is done
anyway.
Is it possible to disable this behaviour, i.e. is it possible to
ensure, that the access key is only working when pressed together with
ALT?
The following xaml shows the issue:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent="Height"
Width="300" WindowStartupLocation="CenterScreen">
<StackPanel Orientation="Vertical">
<TextBox IsReadOnly="True" Text="ReadOnly - give focus and press l" />
<Label Content="_Label:" Target="{Binding ElementName=box}"/>
<TextBox x:Name="box" />
</StackPanel>
</Window>
The solution
Menu and ToolBar menmonics work without pressing Alt key. We decided
that we will have uniform behavior in all cases so access key work
withour pressing Alt key.
I understand that this is not in parity with Forms and we will
consider this issue and change the behavior in the next version.
For now as a workaround you can redister a class handler for all
AccessKeyPressed events and handle the event if Alt key is not
pressed.
EventManager.RegisterClassHandler(typeof(UIElement), AccessKeyManager.AccessKeyPressedEvent, new AccessKeyPressedEventHandler(OnAccessKeyPressed));
private void OnAccessKeyPressed(object sender, AccessKeyPressedEventArgs e)
{
if (!e.Handled && e.Scope == null && (e.Target == null || e.Target == label))
{
// If Alt key is not pressed - handle the event
if ((Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.Alt)
{
e.Target = null;
e.Handled = true;
}
}
}
I added the solution code to the MainWindow class and everything works as expected.
I am using RichEditBox with XAML and C#
I have following 3 events in XAML and corresponding handlers in C#(back code)
DoubleTapped="RichEditBox_DoubleTapped" RightTapped="RichEditBox_RightTapped" PointerReleased="RichEditBox_PointerReleased"
But after putting debug points, I found, none of them is getting triggered.
DoubleTapped event gets triggered if I double tap not on the word but on empty space within the RichEditBox. Once this event is handled, double tap starts working even on words.
I need to handle any of the above events on words. But none of them is responding as expected.
How can I achieve it?
okies. Got other 2 events working as:
SelectionChanged="RichEditBox_SelectionChanged" Holding="RichEditBox_Holding"
Above events mentioned in the question might be a bug, not sure though.
this is a user control and I've got this code XAML:
<RichEditBox x:Name="TextElementControl" Background="{Binding Background, ElementName=userControlModified}" ManipulationMode="None" ScrollViewer.HorizontalScrollMode="Disabled"
AcceptsReturn="True" TextWrapping="Wrap"
SizeChanged="TextElementControlSizeChanged"
IsDoubleTapEnabled="False" DoubleTapped="TextElementControl_DoubleTapped" BorderThickness="0" BorderBrush="{x:Null}" Padding="10,10,10,10"/>
in the code behind :
private void TextElementControl_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
//log message, breakpoint is hitting this during double click.
}
on some portion of the code we've set
void ControlLoaded(object sender, RoutedEventArgs e)
{
TextElementControl.IsReadOnly = false;
}
it works and I hope it helps you.
I'm working on windows phone 8 app, I had a page which inputs number for that I gave code like this,
<TextBox Name="txtNumber" Height="Auto" Margin="0,10,0,510" >
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Number" />
</InputScope>
</TextBox.InputScope>
</TextBox>
by the above code; It display the numeric keyboard when I place the cursor to type; But I need a fixed keyboard which is always visible and if we type it has to enter the value to the textbox.
Would somebody please tell me how to do that.
Try this on for size:
Xaml:
<Grid
x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0"
Loaded="ContentPanel_Loaded">
<TextBox
Name="TB1"
HorizontalAlignment="Left"
Height="72"
Margin="0,74,0,0"
VerticalAlignment="Top"
Width="456"
InputScope="Number"/>
</Grid>
Code:
private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
{
// Turn on Tab Stops. You can set this in XAML as well.
this.IsTabStop = true;
// Set focus on the TextBox.
TB1.Focus();
}
It will spark up the SIP as it enters the <TextBox> ready for input. Hope it's what your looking for.
Got it from this MSDN blog.
The easiest way would probably be with creating your own user control. However it is most likely a lot of work to get it to work as a normal keyboard.
http://www.silverlightshow.net/items/Creating-a-Silverlight-Custom-Control-The-Basics.aspx
Or maybe perhaps this will help http://www.silverlightshow.net/items/Windows-Phone-7-Creating-Custom-Keyboard.aspx