I have 8 small textboxes with a maxlength of 1, and I want to make it so when somebody types a character in one of the boxes it automatically moves the cursor to the next box without the user having to press tab or manually click the next box in win 10 UWp
Is there an easy way to do this?
it automatically moves the cursor to the next box without the user having to press tab or manually click the next box in win 10 UWp Is there an easy way to do this?
The Focus method would be that you want. Pass FocusState.Keyboard as the parameter if you’re setting focus as a result of a keyboard interaction, like a tab sequence or key press.
I have made a simple code sample for your reference:
<StackPanel Orientation="Horizontal" Height="50">
<TextBox x:Name="txb1" MaxLength="1" Width="20" TextChanged="txb_TextChanged"></TextBox>
<TextBox x:Name="txb2" MaxLength="1" Width="20" TextChanged="txb_TextChanged" Margin="10 0 0 0"></TextBox>
</StackPanel>
private void txb_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textbox = sender as TextBox;
if (!string.IsNullOrEmpty(textbox.Text.Trim()))
{
txb2.Focus(FocusState.Keyboard);
}
}
Related
I would like to know a way to make some text appear when you press a button.
I've already created a button and a text box:
<Button Height="25" Width="200" Click="Button_Click" Content="Press this button"/>
<TextBlock Height="50" Width="300" Margin="243,147,249,222" TextAlignment="Center" FontSize="30"/>
Also, I've created a boolean for when you press the button, I don´t know if this is necessary or not.
private void Button_Click(object sender, RoutedEventArgs e)
{
Boolean button = true;
}
Basically, like MaxB said, every control in WPF has a "Visibility" property, that you can change between Visible, Collapsed or Hidden.
Since you already have a Handle for the Button_Click event, all you need to do now is give a name to your TextBlock with the x:Name property like-so :
<TextBlock x:Name="MyTextBlock"/>
Then, in the code of your handler, you can choose which Visibility to apply to the TextBlock according to the state of your boolean.
You can access the TextBlock properties by the name you gave it in the XAML file, like-so :
this.MyTextBlock.Visibility = Visibility.Hidden, for example.
You didn't create a textbox you created a textblock. Firstly create a textbox and give it a name. Then on your Button_click method you can write NameOfTextBox.Text = "Your text";
I am new in UWP, I want to hide On screen keyboard which pops up on focus on textbox.I already have numeric pad to accept the input from user. How to avoid keyboard's automatic functionality.
Tried with PreventKeyboardDisplayOnProgrammaticFocus="True" and
InputPane.GetForCurrentView().Showing += (s, e) => (s as InputPane).TryHide();
but no use.
You can set PreventKeyboardDisplayOnProgrammaticFocus on TextBox to True, this can solve your problem.
Update
When the user clicks on the TextBox, the FocusState of the space is Pointer, not Programmatic, so the PreventKeyboardDisplayOnProgrammaticFocus property does not work.
This is a Hack method that achieves your purpose through visual spoofing:
<Grid>
<TextBox x:Name="HideTextBox" Width="1" Height="1" PreventKeyboardDisplayOnProgrammaticFocus="True"/>
<TextBox x:Name="ShowTextBox" GotFocus="ShowTextBox_GotFocus" IsReadOnly="True" Text="{Binding ElementName=HideTextBox,Path=Text}"/>
</Grid>
code-behind:
private void ShowTextBox_GotFocus(object sender, RoutedEventArgs e)
{
HideTextBox.Focus(FocusState.Programmatic);
}
As you can see, when ShowTextBox is set to ReadOnly, it does not trigger the virtual keyboard. When it gets the focus, we programmatically shift the focus to the "hidden" HideTextBox. At this time, the virtual keyboard will be intercepted. User-entered content can be obtained by binding.
It's not perfect, I also look forward to a better way to solve this problem.
Best regards.
I created a UserControl, and added a Button inside it removing the Background and Text properties:
<Button x:Name="Button"
HorizontalAlignment="Center"
Height="40"
VerticalAlignment="Center"
Width="40"
RenderTransformOrigin="0,-2"
Margin="0,0,0,0"
BorderBrush="{x:Null}"
Click="Button_Click"
Background="{x:Null}"/>
I also hadled the Button Click event as below:
private void Button_Click(object sender, RoutedEventArgs e)
{
Button.Content = new cross();
}
The above code fills the Button content with another UserControl which is a simple cross pic.
I have placed the UserControl with the Button into a MainWindow app and after pressing Button, it starts blinking - background is fluently changing between two colours. Beside my functionality from code works good. I just don't know how to get rid of that blinking background.
Before click:
After click:
You could set Focusable="False" at your Button to achive this.
But you should read about the Focusableproperty in the MSDN to check if it's ok for you. I guess you can't focus the Buttonusing the tab key anymore. But maybe that's not a problem for you.
I are facing issue with GridView Control. We had a working Windows Store App on 8.1 where GridView left and right mouse clicks had different functionality. In the case of left mouse click, we used to use “ItemClick” event which performs navigation to another XAML page. On right click of GridItem, it gets selected and shows the appbar, we have used “SelectionChanged” event for this.
We are now migrating our existing windows store app to UWP Application, we have used same gridView Code, we find significant difference in functionality and look & feel, we don’t see GridView Item Selected like above picture. We see “ItemClick” and “SelectionChanged” are working together. The flow is something like that on left click on the item, the control goes to SelectionChanged event and then ItemClick. We were not able to differentiate actions like Left Mouse Click and Right Mouse click, since both events are getting fired up upon clicking on left click/tapping. We have different functionality on left and right clicks of mouse.
Need help on how to mimic windows 8.1 functionality in UWP.
My requirement was the I wanted to use Right Click/Long Tapped to select an item and take an action accordingly from App Bar Buttons and on Left Click/Tap should redirect me to the next XAML Page. The problem I was facing was the on Right Click, I wasnt able to detect that which items of GridView has been clicked and how can I add that into SelectedItem.
What I did was, I introduced extra Grid in DataTemplate of GridView. Within this Grid, I added RightTapped event.
The sample code snippet is
<GridView x:Name="ItemGridView"
ItemsSource="{Binding Source={StaticResource ItemsViewSource}}"
IsItemClickEnabled="True"
SelectionMode="Single" ItemClick="ItemGridView_ItemClick"
SelectionChanged="ItemGridView_SelectionChanged">
<GridView.ItemTemplate>
<DataTemplate>
<Grid RightTapped="Grid_RightTapped">
<Border Background="White" BorderThickness="0" Width="210" Height="85">
<TextBlock Text="{Binding FileName}" />
</Border>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
The event name is Grid_RightTapped. This helped me detect that from which GridViewItem, I got the long tap/right click.
The code-behind for this is:
private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
Song selectedItem = (sender as Grid).DataContext as Song;
//the above line will get the exact GridViewItem where the User Clicked
this.ItemGridView.SelectedItem = selectedItem;
//the above line will add the item into SelectedItem and hence, I can take any action after this which I require
}
}
The reason we are doing this way is, because now we can add clicked item into the GridView SelectedItem using Right Click. Now in UWP, clicked items are added into SelectedItem using left click only. And with left click, I can navigate to another page using ItemClick event.
You are correct, there has been a change in the interaction model behavior. According to MSDN article How to change the interaction mode (XAML)
For selection, set IsItemClickEnabled to false and SelectionMode to
any value except ListViewSelectionMode.None and handle the
SelectionChanged event (ItemClick is not raised in this case).
For invoke, set IsItemClickEnabled to true and SelectionMode to
ListViewSelectionMode.None and handle the ItemClick event
(SelectionChanged is not raised in this case).
Another combination is to set IsItemClickEnabled to false and
SelectionMode to ListViewSelectionMode.None. This is the read-only
configuration.
A final configuration, which is used least often, is to set
IsItemClickEnabled to true and SelectionMode to any value except
ListViewSelectionMode.None. In this configuration first ItemClick is
raised and then SelectionChanged is raised.
You seem to be using the last option - IsItemClickEnabled is set to true and SelectionMode is set to something that's not None. According the Microsoft, this is used least often so maybe it would be a good idea to rethink this design?
Since you haven't shared any code that you already tried, I will just throw in one idea: maybe playing around with Tappedand RightTapped event handlers could help you differentiate between the two more easily?
To identify left and right click, for right click you can use RightTapped event
<GridView x:Name="categoryItemsGV"
Margin="5,5,0,0"
IsItemClickEnabled="True"
ItemClick="categoryItemsGV_ItemClick"
IsRightTapEnabled="True"
RightTapped="categoryItemsGV_RightTapped"
SelectionMode="Single"
SizeChanged="categoryItemsGV_SizeChanged"
ItemsSource="{Binding}">
and .cs code is below:
private void categoryItemsGV_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var tablemod = (sender as GridView).SelectedItem;
}
From RightTapped the item over which the mouse was right clicked can be obtained from e.OriginalSource
<GridView x:Name="myGridView" VerticalAlignment="Center">
<GridView.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Reset"/>
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="Repeat"/>
<MenuFlyoutItem Text="Shuffle"/>
</MenuFlyout>
</GridView.ContextFlyout>
</GridView>
Private Sub myGridView_RightTapped(sender As Object, e As RightTappedRoutedEventArgs) Handles myGridView.RightTapped
myGridView.SelectedItem = e.OriginalSource
End Sub
Now that RightClick has selected the desired item, further action like delete, copy can be executed on it.
I have a textbox with a button inside (Telerik's RadTextBox with an Action configured).
When the user presses the Action, a progress bas is displayed, the screen goes dark, and some magic happens.
My problem is that since the action doesn't result in the textbox losing focus, the on-screen keyboard is not hidden, and keeps covering half the screen.
I would like to programmatically hide the on-screen keyboard, but don't know how.
Just set focus to the main page:
this.Focus();
this will focus a control that doesn't use the keyboard and thus hide the keyboard. Unfortunately there is no API to the keyboard to hide it.
Instead try disabling and then enabling the textbox in question in an appropriate place (like once a query has been submitted or an action triggered):
TextBox.IsEnabled = false;
TextBox.IsEnabled = true;
(Via https://stackoverflow.com/a/23905874/1963978)
Not clean, but it does the job (in Windows 10 mobile).
here lot solution is available for a Textblock only but in my case AutoCompleteBox
<toolkit:AutoCompleteBox Name="autoComplateTxt"
Grid.Row="4"
Margin="15,5,2,10"
Padding="0"
Height="65"
Text=""
BorderThickness="1"
BorderBrush="Black"
VerticalAlignment="Center"
DropDownClosed="autoComplateTxt_DropDownClosed"
/>
private void autoComplateTxt_DropDownClosed(object sender, RoutedPropertyChangedEventArgs<bool> e)
{
this.Focus();
}