How to restore default style for CheckBox on ToolBar? - wpf

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.

Related

WPF TextBox in DataTemplate of ToggleButton does not show text if in toolbar flyout

If I put the Column where the toolbar is hosted to be very big (800) then all the text is visible:
but if I put a smaller column this happens:
But I cannot understand why:
<DataTemplate x:Key="IconFilterButton">
<StackPanel Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource LargeIconStyle}"
Text="{Binding}" />
<TextBlock
Margin="6,0,0,0"
VerticalAlignment="Center"
DataContext="{Binding}"
Style="{StaticResource BodyTextStyle}"
Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToggleButton}, Path=Tag}" />
</StackPanel>
</DataTemplate>
and here the definition
<ToggleButton
x:Name="DFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1d"
/>
<ToggleButton
x:Name="WFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1w"
/>
Even worst if I click on the button once they are out:
and then the text is visible but is wrong as the TextBlock is not considered in the object size:
The WPF ToolBar control uses a custom panel for the overflow Popup. In many styles, the ToolBarOverFlowPanel has a property WrapWidth set to a static value like 200. This determines how many items can be displayed before it wraps to another row in the popup.
I've created custom styling for this control and have found that the ToolBarOverFlowPanel used internally is buggy. That's probably the source of your problem.
You can re-template the ToolBar and wire-up a different value for WrapWidth to try to fix the issue, but my guess is that you'll still run into layout problems.
Otherwise, you might consider making your own replacement control.

Why does WP7 ListPicker have different margins and height to TextBox

I have a page in my WP7 app consisting of a TextBox beside a ListPicker. In their default modes, they don't line up properly; the ListPicker has a different padding to the TextBox, and its height is also different.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Orientation="Horizontal">
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"/>
<toolkit:ListPicker Width="170" ItemsSource="{Binding l}" Style="{StaticResource ListPickerStyle1}" VerticalAlignment="Top"/>
</StackPanel>
</Grid>
Manually tweaking the ListPicker's template to fit in correctly here is tricky and error prone. For example, when its height is adjusted, the caption (i.e. the text of the selected item) is no longer in the centre of the component.
My app is currently failing MS app review because the components are not all the same height.
Is there an easy way for me to set the toolkit:ListPicker to have the same appearance as a TextBox?
The simplest solution will be to take a copy of the the default style and tweak that using Blend to be exactly how you want it to look. This will take a little trial and error to sort out.
You can then use the implicit styling rules to apply it to all ListPickers without having to explicitly set the style on each instance:
<Style x:Key="MyListPickerStyle
TargetType="toolkit:ListPicker>
.... your tweaks here
</Style>
<Style TargetType="toolkit:ListPicker"
BasedOn="{StaticResource MyListPickerStyle}" />
It may be easier to tweak the TextBox Style of course :)

How can I apply the style of a ToolBar CheckBox to a regular CheckBox?

I would like to style a regular CheckBox so it looks like a CheckBox inside a Toolbar:
<StackPanel Orientation="Horizontal">
<CheckBox Style="{What to put here?}">
<Image Source="someImage.png" Stretch="None" />
</CheckBox>
</StackPanel>
Is there a way to obtain a reference to the Style use by the ToolBar and 'bind' to it?
EDIT: The reason for this is because I want a few simple buttons to control the Visibility of some elements and I don't want to use a ToolBar just for this.
Never mind, I found the solution:
<StackPanel Orientation="Horizontal">
<CheckBox Style="{StaticResource {x:Static ToolBar.CheckBoxStyleKey}}">
<Image Source="someImage.png" Stretch="None" />
</CheckBox>
</StackPanel>
I think you might need to use a ToggleButton or make a control template, You might find the following urls useful:
http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.aspx
WPF CheckBox with "Button" appearance

Silverlight 4 tab order problem?

I’d like to find out if I am missing something in my XAML code related to the tabbing. In my case, I need to click twice to be able to advance to the next control in the tab order. It will be great to find out the proper way applying tabbing in Silverlight 4. Below is the code I use for tabbing. Thank you in advance!
<StackPanel x:Name="sp" Grid.Column="0" >
<TextBlock x:Name="txtO" Style="{StaticResource AVV_TitleStyleBlue}" Text="Text" />
<HyperlinkButton x:Name="hl1" Style="{StaticResource AVV_HyperlinkButtonStyle}" Content="test 1" IsTabStop="True" TabIndex="11" />
<HyperlinkButton x:Name="hl2" Style="{StaticResource AVV_HyperlinkButtonStyle}" Content="test 2" IsTabStop="True" TabIndex="12"/>
<HyperlinkButton x:Name="hl3" Style="{StaticResource AVV_HyperlinkButtonStyle}" Content="test 3" IsTabStop="True" TabIndex="13" />
<HyperlinkButton x:Name="hl4" Style="{StaticResource AVV_HyperlinkButtonStyle}" Content="test 4" IsTabStop="True" TabIndex="14" />
</StackPanel>
You might have the issue where a sub control is also getting the tab, i guess that since you need to tab twice. On the first tab is most likely taking you to a hidden control, The second tab then takes you to the control you want. To fix this you need to find out what control the focus is going to when you hit Tab. You can do that by using the Focus Manager's get Focused Component method; you put that in a place just after you hit tab, you may need a small delay before getting the control. Then you set a break point in VS, and get the info about that control. Once found you set its IsTabStop Property to false. If you are using a third party control, you will need to change its template maybe using expression blend.

WPF CheckBox with "Button" appearance

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>

Resources