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>
Related
I am a newbie to the programming. So I am always confusing the differences between these controls.Difference between Togglebutton and Radiobutton controls in Xaml?
Let's take a real example for this
Toggle Button: As the name suggest a button whose state can be toggled from on to off or vice-versa. For example a Switch in your home to turn a particular light on or off.
Radio Button: Its name comes from the concept of buttons in Radio where for first station you press first button and for second station you press second button and so forth. So you can choose from multiple options. But at a time only one will be selected.
Toggle Button : Like you can use ON/OFF [Change between states]
Radio Button : Select one from list [Select one from group of option]
ToggleButton has two positions right and wrong, but for multiple
RadioButton with the same Groupname property, only one can be true at a time.
If radio button and toggle button are not part of the toggle group, their behaviour is same.
If radio button and toggle button are part of the toggle group, radio buttons can’t be deselected, but toggle button can.
I want to display some options like textbox, combo boxes, and labels when a radio button is checked. How can I do that?
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.
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>
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?