Windows Phone 7: How do I make a radiobutton look like a toggle button?
I am trying to get the selected radio button to look like a depressed button.
Basically I have a filter by 'FName', 'LName' radio button over my list of names. RadioButton takes up too much screen space. A depressed button will save the space used by the 'O'
You can try changing your Xaml to specify a ToggleButton which is the base class for RadioButtons and CheckBox's, but since it is a ToggleButton you will have to interlock them in the Checked and UnChecked events. See this article and this MSDN information. Your only other option would be to create a new Style for your RadioButtons.
From:
<RadioButton Content="First Name" Height="72" HorizontalAlignment="Left" Margin="38,92,0,0" Name="FName" VerticalAlignment="Top" Width="102" />
To:
<ToggleButton Content="First Name" Height="72" HorizontalAlignment="Left" Margin="38,92,0,0" Name="FName" VerticalAlignment="Top" Width="102" />
You can only do this if you overwrite the template radio button.
In WPF, we can use the following "hack":
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" />
I believe that this does not work for WP7.
I suggest you create your own style of 0.
You can use the Expression Blend to facilitate your work. Look about writing styles that should help.
Related
I'm using MahApps.Metro for my WPF app. As shown in the image below, the Forground color of a CheckBox remains default (black) if I try to change it to white.
Question: How can we change the content color to white?
None of the following XAMLs change the content's forground color. It remains default (black):
<CheckBox x:Name="chkTest" Content="Test Content" FontSize="20" Foreground="{StaticResource MahApps.Brushes.Badged.Foreground}" />
Or:
<CheckBox x:Name="chkTest" Content="Set Default" FontSize="20" Foreground="White" />
Or -as discussed here:
<CheckBox x:Name="chkTest" Content="Test Content" FontSize="20" Foreground="{StaticResource MahApps.Brushes.CheckBox.ForegroundChecked}" />
Display of the above XAMLs:
The MahApps.Metro CheckBox style has many states and triggers, which use different brushes. Overriding the Forground property does not cover all states.
However, there is a dedicated type CheckBoxHelper with many attached properties that you can use to customize every brush in each state for the content, as well as for the check mark glyph. Look for properties starting with Foreground... and CheckGlyphForeground.... There are attached properties for check mark and content background as well.
<CheckBox x:Name="chkTest" Content="Set Default" FontSize="20"
mah:CheckBoxHelper.ForegroundUnchecked="Blue"
mah:CheckBoxHelper.ForegroundUncheckedMouseOver="Green"
mah:CheckBoxHelper.CheckGlyphForegroundChecked="Red"
mah:CheckBoxHelper.CheckGlyphForegroundCheckedMouseOver="Purple"/>
Am using devexpress wpf tools version 17.1. I am using Light Gray theme in the application.
Here is my xaml for radio buttons
<RadioButton Content="Forms"
Grid.Row="0"
GroupName="ActionGroup"/>
<RadioButton Content="All Questions"
Grid.Row="1"
GroupName="ActionGroup"/>
<RadioButton Content="Current Question"
Grid.Row="2"
GroupName="ActionGroup"/>
Here is the output
the content is top aligned, want to make it center with image. I placed these radio buttons in dx:GroupFrame, the groupframe header also has the same problem, header is stop aligned.
did you try to set the VerticalContentAlignment Property of the RadioButtons to Center?
Something along this lines:
<RadioButton Content="Current Question"
Grid.Row="2"
VerticalContentAlignment="Center"
GroupName="ActionGroup"/>
Problem is that ToolBar w/o any permission changes style of placed CheckBox (instead of tick box it looks like normal button). I want to restore original look of CheckBox with a minimum code.
This problem is opposite to the problem described here: How can I apply the style of a ToolBar CheckBox to a regular CheckBox?
Any help, please?
You're probably looking for:
<CheckBox Style="{x:Null}" />
This should restore the default checkbox style.
Well... it is not anarchy :o) this is the normal behavior from the toolbar. Maybe there is another way, but you can wrap your checkbox in a, let's say, Dockpanel to hide the style the Toolbar applies to the CheckBox.
Something like this would work:
<DockPanel>
<CheckBox Content="Check 1"/>
<CheckBox Content="Check 2"/>
</DockPanel>
I actually stumbled on the answer. Try this:
<BulletDecorator
Margin="0,5,0,0">
<BulletDecorator.Bullet>
<CheckBox />
</BulletDecorator.Bullet>
<TextBlock
Width="100"
TextWrapping="Wrap"
HorizontalAlignment="Left"
Foreground="Blue"
Margin="5,0,0,0">
Some text
</TextBlock>
</BulletDecorator>
with, of course, modifications per your needs.
I need a button-like control that can have a Checked property, so that when clicked it stays pressed.
I had that functionality in WinForms, with the CheckBox control, setting the Appearance property to "Button".
Can someone help me?
Use a ToggleButton, it has all the functionality you see in a CheckBox since it is derived from it.
WPF has a built-in ToggleButton control that serves this purpose. If you need to change the visual appearance of this default control you will need to apply a new Template (ControlTemplate) to it.
<Window.BindingGroup>
<BindingGroup Name="{x:Null}" NotifyOnValidationError="False" />
</Window.BindingGroup>
<Grid>
<nit:checkbutton1 x:Name="button1" Margin="32,88,0,0" Click="checkbutton1_Click" HorizontalAlignment="Left" Width="31" Height="32" VerticalAlignment="Top" mode="{Binding ElementName=cb1, Path=SelectedItem}" />
<ComboBox x:Name="cb1" ItemsSource="{Binding Source={StaticResource modeEnum}}" IsSynchronizedWithCurrentItem="True" Height="23" Margin="0,97,24,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="112" />
</Grid>
I have a Silverlight menu for my application with an image as the background. I use some empty HyperlinkButton at a specific position and size to simulate a real button on the image (think as a HTML image-map):
<HyperlinkButton x:Name="Portfolio" Width="86" Height="40" Canvas.Top="50" NavigateUri="/portfolio"/>
<HyperlinkButton x:Name="Analysis" Width="79" Height="40" Canvas.Top="50" Canvas.Left="124" NavigateUri="/analysis" BorderThickness="0"/>
<HyperlinkButton x:Name="News" Width="77" Height="40" Canvas.Top="50" Canvas.Left="240" NavigateUri="/news"/>
<HyperlinkButton x:Name="Questions" Width="80" Height="40" Canvas.Top="50" Canvas.Left="357" NavigateUri="/questions"/>
<HyperlinkButton x:Name="Companies" Width="80" Height="40" Canvas.Top="50" Canvas.Left="477" NavigateUri="/companies"/>
The problem is when I click these buttons it shows a bluish border corresponding to the hyperlink button area during the click event. There is a way I can avoid showing that?
I found the answer in other blog, just set IsTabStop="False" in the HyperLinkButton instance.
For info on styling controls, see http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx (skip down to the Customizing Controls using Control Templates section halfway down). If you want to start with the default style (usually a good idea--start here and add/change/remove things until you get what you want) look here: http://msdn.microsoft.com/en-us/library/cc296242(VS.95).aspx.
In this case, I believe the offender is the "FocusVisualElement." You could either change the color of it, set visibility to "Collapsed," or remove/change the "Focused" state so the storyboard isn't run.
You can edit a template of HyperlinkButton in Blend:
1.right click on control choose "Edit Template->Edit a copy"
2.in "States" panel click "Pressed"
3.change property "Stroke" of rectangle named "FocusVisualElement" from solid color to "No brush"
http://silverlight.net/forums/t/40896.aspx