Silverlight 4 tab order problem? - silverlight

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.

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.

Wpf, AvalonEdit and keyboard navigation problem

I have an AvalonEdit on my window. When I press key combination Ctrl+Up or Ctrl+Down when inside editor, AvalonEdit loses focus, which is transferred to a different control, as below:
This sometimes happen as well when using Ctrl+Left or Ctrl+Right combinations.
My current XAML definition looks like following:
<ae:TextEditor x:Name="teEditor"
Grid.Row="0"
Grid.Column="0"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderThickness="0"
FontFamily="Consolas"
FontSize="10pt"
TabIndex="0"
WordWrap="{Binding ElementName=Root, Path=Handler.WordWrap}"
ShowLineNumbers="{Binding ElementName=Root, Path=Handler.LineNumbers}"
ContextMenu="{StaticResource EditorContextMenu}"
GotFocus="HandleEditorGotFocus"
KeyboardNavigation.ControlTabNavigation="None"
KeyboardNavigation.AcceptsReturn="True"
KeyboardNavigation.DirectionalNavigation="None"
KeyboardNavigation.TabNavigation="None"/>
How can I prevent that?
It turns out, that problem appears, when you place AvalonEdit inside TabControl. In such case you have to disable keyboard navigation on the TabControl by adding:
KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.DirectionalNavigation="Contained"

WPF Scrollviewer on touch screen tablet

I'm writing a WPF application that is going to run on a full windows 8 touchscreen tablet (not RT).
However touch scrolling doesn't seem to be working. So I'm wondering if it's something I'm doing wrong or if it's even possible?
So, I have a WPF window with a scrollviewer. Within that scrollviewer I have a StackPanel which has loads of textblocks within it. See below:
<ScrollViewer>
<StackPanel>
<TextBlock Text="Row 1" />
<TextBlock Text="Row 2" />
<TextBlock Text="Row 3" />
<TextBlock Text="Row 4" />
<TextBlock Text="Row 5" />
<TextBlock Text="Row 6" />
....
<TextBlock Text="Row 50" />
</StackPanel>
</ScrollViewer>
Now using the touchscreen I try to scroll the contents but it doesn't move. I can only scroll the contents using side scollbar which is not how I want this to work. Is it possible to get touch scrolling working with WPF? I'd also want to do the same with the grid.
Thanks in advance.
I'm using Visual Studio/Blend 2012.
You can enable scrolling with the PanningMode property like this:
<ScrollViewer PanningMode="Both"></ScrollViewer>.
See: MSDN
Mouse support
If you want to implement this behavior with the mouse, please read this article.

WPF: Expand the validation rectangle

This is my current XAML.
<StackPanel Orientation="Horizontal" Grid.Column="3" Grid.Row="1">
<Label Content="Allocated:" FontSize="14"/>
<Label Content="{Binding AllocatedUnits, Mode=OneWay, ValidatesOnDataErrors=True}" ContentStringFormat="N0" FontSize="14"/>
</StackPanel>
How would I change this so that the red validation rectangle is around the whole text instead of just the number. (I will accept throwing away the stack panel entirely and doing something else.
A string-formatted binding would probably do the trick in this case, but that wasn't available in .NET 3.0 (in case you're still using that version!). If you can use it, you'd only need a single label control (so you can ditch both the other label and the stackpanel, and your validation border will wrap all the text in the remaining label).
EDIT: as per Jonathan's comment, it seems you need two attributes to do this on a content control...
Use something like this for your binding:
Content="{Binding AllocatedUnits, ValidatesOnDataErrors=true}" ContentStringFormat="Allocated: {0}"
MSDN documentation is here.

Silverlight 3 Checkbox Listbox bug when scrolling?

I've spent a few minutes searching on Google and have not found anything related to this issue I'm having:
Today I upgraded to the Silverlight 3 SDK and converted a project that I'm working on. I then noticed a bug in my program with a Listbox that has a Checkbox as its DataTemplate.
When one or more items is checked, and I scroll up and down, it seems that a few of the Checkboxes at the extremes get checked off and on randomly. This does not trigger the Checked/Unchecked event, however.
Has anyone seen this behavior? I'm not doing anything out of the ordinary, simply scrolling up and down once at least one checkbox has been checked, and a couple of others that I have not touched seem to get checked on and off repeatedly. This was definitely not happening with the Silverlight 2 SDK.
Here's the XAML definition for my Listbox:
<ListBox x:Name="cBoxSalesmen" Width="135" Height="200"
HorizontalAlignment="Left" VerticalAlignment="Top">
<ListBox.Template>
<ControlTemplate>
<Border Style="{StaticResource BorderStyleThin}">
<StackPanel Orientation="Vertical">
<TextBlock Text="Salesmen" />
<ScrollViewer Height="176" VerticalScrollBarVisibility="Visible" >
<ItemsPresenter />
</ScrollViewer>
</StackPanel>
</Border>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Margin="0" Content="{Binding}" FontSize="10" HorizontalAlignment="Left"
Checked="SalesmenCheckbox_Checked" Unchecked="SalesmenCheckbox_Unchecked"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The default ItemsPanel of the ListBox is the VirtualizingStackPanel. You can change it to use the StackPanel, this way you problem is solved.
Use this code:
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
<ListBox.ItemsPanel>
I suspect your problem is a result of ListBox (in SL3) now using an ItemCollectionGenerator. The concept behind this is that not all the objects found in the source data collection need to have had their corresponding instance of the DataTemplate created and added to the Visual Tree. As you scroll toward the bottom items that may soon be needed are created. Additionally items that have already be created but are now scrolled quite same way out of view can be removed. If the user scrolls up they are re-created.
If this is the case then the IsChecked state of any checkbox in this list will be lost at some point for large lists. To solve this you would need include a property in the data type to which you can bind IsChecked. Hence as ListBox re-creates items it correctly assigns the IsChecked value.

Resources