How to create toggle buttons in Windows 8? - windows-8

I need to create a group of 5 buttons. Only one can be pressed, like Radio Button, but I do not want to show the circle. I would like to use the button look.
Somebody do know which is the best way to do it?
I have found for WPF:
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" />
but it does not work for Windows 8.
Thank you

Is this a group of actual buttons with an action assigned to the click event of each, or are you just trying to remove the circle form a RadioButton type control?
Please note that the user will likely expect a RadioButton control to look and feel like a RadioButton. Changing this just for the sake of it may not be a good idea, but if you want to go ahead with it you could try one of the following options.
1) Edit the template for a radiobutton control to hide the selcetion circle. (I don't know if that's even possible in all honesty, but in theory, it should be)
or
2) Emulate the behaviour with a ListView with SelctionMode set to "Single"
Things get a little more complicated if you want to handle click events on each "button", but it is not impossible. In your ItemTemplate, add a button (presumable with a style of "TextButtonStyle") and set the event handler of the Click event to check which button was pressed and act accordingly.

There is a control called ToggleButton, why don't you use that?

Related

How to prevent auto-selection of radio buttons

When adding an instance of the Gtk# RadioButton class to a GUI, it is automatically checked ("activated") as the first member of its radio button group.
For Gtk, this has been discussed to some extent in another question, with the main point of the selected answer being that users expect one radio button to be selected at all times.
I do not dispute that.
However, I am automatically generating my user interface in a way so each radio button is linked to a data model, but none of the radio buttons can, at any time, get a reference to any of the other RadioButton instances. The data model ensures that one radio button is checked at all times.
Beside being sufficient to match user expectations, I consider this good practice, as like this, data integrity is ensured by the data model, not by the GUI.
Unfortunately, Gtk# will automatically check all radio buttons like this, as it considers each radio button to be the first in its group. For adding the various radio buttons to the same group, I would have to pass the first radio button in the group to the constructor of the other radio buttons - which I cannot, as pointed out above, as I do not have any way to get the reference to that first radio button when instantiating the others.
Setting the Active property of the radio button to false does not help, nor does invoking the Toggle method.
Is there any way to suppress this automatical selection, possibly by subclassing and overriding something I could not find yet? Alternatively, is it somehow possible to force a CheckButton to look like a radio button for this purpose?
If there is really no other solution, I will try and implement the solution suggested in another answer that involves adding a second hidden radio button for each of my radio buttons, but I would find that extremely hacky for production code.
Extension to Josip's solution: Create your own radio button widget, actually containing nothing else than two gtk radio buttons, one of which always is hidden. Your factory then creates this one instead of the original gtk button...
Radio buttons are similar to check buttons except they are grouped so that only one may be selected/depressed at a time.
They require a group to perform their duty properly.
Try the solution from the down, it's not so hacky, just try to add one hidden radio button that is always selected.

TextBox gaining unwanted focus

I have a simple xaml page with one TextBox and a RichTextBlock.
Inside that RichTextBlock there are some InlineUIContainers.
But when the user presses a button, I remove through code an InlineUIContainer. This goes well, but each time this is done, the TextBox that is on the page get's focus!
Resulting in the touch keyboard popping up. Anyone an idea why this is happening? Or how I can prevent this?
I can't set the IsTabStop, because the user still has to be able to fill something in if needed.
I'm working on the Windows Phone part of a WinRT Universal app
Some code, but the actual removal is done in the Attached Dependency Property
It's the KeywordsInput textbox that get's the focus after each removal
<TextBox x:Uid="Search_KeywordsInput" x:Name="SearchKeywordsInput"
Text="{Binding KeywordsInput, Mode=TwoWay}" />
<RichTextBlock Grid.Row="4"
Margin="0,9.5,0,0"
IsTextSelectionEnabled="False"
dependencyProperties:RichTextBlockTagCloud.Command="{Binding SelectedTagFilterCommand}"
dependencyProperties:RichTextBlockTagCloud.TagItems="{Binding SelectedFilters, Mode=TwoWay}">
<Paragraph x:Name="TagsFilters" />
foreach (InlineUIContainer container in buttonsToRemove)
tagParagraph.Inlines.Remove(container);
Have you try to set IsTabStop=False on Button, so clicking button doesn't steal RichTextBox focus.
If you remove the focused control then the focus will move to a valid control. In this case, the next control found is your TextBox. If you park the focus on a benign (non-text) control before removing the focussed button then the keyboard won't trigger.
Depending on your overall layout you may be able to set the focus to the page, you may have another button which would make sense, or you could add a non-editable control to the tab order.

How to create a display mode and edit mode in a Metro App?

What is the best approach to change TextBlocks to TextBoxes after clicking on Edit button for a Windows 8 Store App? This is something similar to an iOS app that after clicking on an Edit button editable fields become TextBoxes and you can then change data.
You don't need to use TextBlock just use TextBox with IsReadOnly property.
on button click mark the IsReadOnly="True"
I think you want the IsReadOnly property. IsReadOnly=true; when you don't want to let them edit the textbox, IsReadOnly=false; when you want to let them edit it.

Detecting a scroll event in GridView (Windows 8)

How do we detect a scrolling event in GridView (like ViewChanged on ScrollViewer) on somethig like the default GridView template sample app? I'd like to replicate the effect that the netflix App does on the left red strip.
I tried putting the GridView inside a scrollviewer, but I've been unsuccessful at stretching it to fill the screen for different resolutions.
Update: I intend to use this with VariableGrid control that's on NuGet - though it's not an official control, it inherits GridView
The best way to do this seems that you can read through the components of the control, and assign events to it. based on what's happening in this example
http://mikaelkoskinen.net/post/WinRT-XAML-Automatically-Scrolling-ListView-to-Bottom-and-Detecting-When-ListView-is-Scrolled.aspx
I grabbed access to the scrollbar, suing the VisualTreeExtensions and I could capture the event Scroll, just like in the example. I had to read the children when the Loaded event of the grid was fired.
There is a simpler way.
Edit a template of the GridView, and look inside the XAML to find a ScrollViewer which is a component of the GridView.
The ScrollViewer has a ViewChanged event that you can subscribe to. Now whenever the GridView is scrolled, this event will be fired.
Try ManipulationCompleted and PointerReleased events on GridView. This is just using keyboard mouse..

Simulate Winforms Button Click Animation

I have a button and inside my button I have an image control. When the users click on the image I'd like to animate the button so it appears the button was pressed. I don't really care whether the actual button press event fires or not--it's the illusion of a button press I want to see.
Note: the only options I see on the web involve writing directly to the Windows API--a level of complexity and non-upgradability I really don't want to get into.
Why not just use two different images, one for a normal state, and another for when your button is being pressed.
If you want to go for more complicated route try using GDI+. Here is a quick sample tutorial on how to do this.
Why are you using an image control inside your button control instead of using the button control's Image property?
Using the Image property of the button will give you a button with an image that the user can press and that will raise the OnClick event without doing any extra work or re-implementing features that are already available.
I ended up making my picturbox look like a button by giving it a raised border style. Then on the mouseclick event I simulate the look of a button press by changing the border style for a few hundred miliseconds.
Private Sub simulateButtonPress(ByRef pictureBox As Infragistics.Win.UltraWinEditors.UltraPictureBox)
pictureBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Inset
Application.DoEvents()
System.Threading.Thread.Sleep(400)
pictureBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Raised
Application.DoEvents()
End Sub