How to switch focus from one textbox to another when we tap the tab button in WinRt apps? - winrt-async

In My WinRt apps,I need to tap twice on tab button for switch focus from one textbox to another. but i want to switch focus from one textbox to another in single tap on tab button. Please give me correct solution

This works on my app :
myTextBox.Focus(FocusState.Keyboard);
myTextBox.Focus(FocusState.Pointer);
myTextBox.Focus(FocusState.Programmatic);

Most of the time, there is nothing to do to get the tab working.
If you need to press the TAB key twice, you are probably giving the focus to a control you do not expect because the tab order is not what you expect.
You can force the focus order by specifying the TabIndex property on your controls. In this way, you are sure about what will happen when pressing TAB.
<StackPanel>
<TextBox TabIndex="1" />
<TextBox TabIndex="2" />
<TextBox TabIndex="3" />
</StackPanel>

Related

how to toggle two different radio button in wpf

I have a requirement where I will display two radio buttons using MVVM Model. Assume it as A and B.
If a user selects A radio button B radio button should be unchecked.
if a user selects the B radio button A radio button should be unchecked.
As #Clemens and #Michel_Fehr has suggested, you will have to use the same group for both the radio buttons.
The code will look something like this:
<StackPanel Margin="10">
<RadioButton GroupName="myGroup" IsChecked="True">A</RadioButton>
<RadioButton GroupName="myGroup">B</RadioButton>
</StackPanel>

Have Checkbox checked by default in UI

I am trying to add a new checkbox into a UI screen for my installer.
So far I have declared the property as seen below:
<Property Id="RS232" Value="1" Secure="yes"/>
And in the UI, my checkbox has been added as:
<Control Id="myNewCheckbox" Type="CheckBox" X="200" Y="170" Text="Generic Driver" Width="130" Height="15" Property="RS232" CheckBoxValue="1"/>
From documentation I have read I am lead to believe that as long as CheckBoxValue and Value are equal i.e 1 in this case, then the checkbox should be checked by default.
There are already existing checkboxes on this same UI and this is true for them, so I do not understand why in my additional case, the checkbox is not active.
Another note to be made is that when I go through the installation process to test the new checkbox, the dialog disappears when I hover over it with a mouse and I am unable to check/uncheck the box.
I first thought that perhaps the Width field for the text was not big enough, but I have tested by expanding this with no results.
Any help is appreciated!

How to set a prompt for combobox with mixed items?

There are nice solutions to the problem with combobox and prompt in WPF, but in my case I have mixed items -- image and text. So for example this solution (copied from https://stackoverflow.com/a/11671997/210342):
<ComboBox Name="MyComboBox"
IsEditable="True"
IsReadOnly="True"
Text="-- Select Team --" />
works fine as for prompt, but it has side effect, that when I select an item, the item in turn is not displayed correctly as selected -- it is presented in list OK, but after selection all combobox shows is System.Windows.Controls.ComboBoxItem.
So how to have a prompt (I don't insist of fixing this approach) and properly displayed mixed items?
I solved this in ugly way. I added a grid, put this combobox in the grid with ZIndex=0. I added extra button to the grid with ZIndex=1. This way I get an overlay. Any time users clicks on the button (combo is initially hidden) I open combobox programatically. When users selects anything from dropdown list of the combobox I hide the prompt button.

Preventing initial focus

I have a button that, when it has focus, has a special style.
I have a form with only a series of these fancy buttons; when it loads, the first button in the series is displaying the special style to indicate it has focus. It's functionally fine, but visually annoying.
I have resolved this with:
<TextBox width="1" Height="1" />
But this feels like a kludge.
Is there a better way to prevent anything from having the initial focus?
By default, focus should be on window and not on button. Are you unknowingly, setting focus on button either using focus method or tab index?

Stop containing button from handling input - Silverlight

I'm working on a custom button where the content is sometimes a textbox. I'm doing this so I have a sort of edit-in-place where you can type text, hit enter, and then the textbox disappears and the button's text is what was typed.
So as a simple case, you could mock this up like so:
<Button>
<TextBox />
</Button>
The problem is if you hit the <space> or <enter> while typing it'll "click" the button instead of input those keystrokes into the textbox.
Now, like I said, this is a custom button so I can do whatever I need to in the codebehind to get this working.
Just because a TextBox appears over a Button does not mean it should be inside the button :)
You are better off with a custom control that has a button with optional Textbox over it. That way the TextBox will not interfere with the button beahaviour. If you put them both in a grid you will still retain a lot of dynamic layout control.
You will just need to expose properties and events of the button (and probably of the TextBox) on your user control.
If you need specific help, just ask.

Resources