Back in the ancient days in VB6, two different controls could not have the same TabIndex. If I tried to assign a control with the same index as another control, the other control's index would be scooted up sequentially in the tab order.
Now in .NET, I see 2 controls have the same index.
How can this make sense?
Is there a utility to easily set the sequence without having to iterate through the property grid?
No, the designer doesn't 'fix' the TabIndex you set. There's an interactive tool to set them. Use View + Tab Order and click the controls in the order you want to tab them.
Related
I have a WPF/XAML form that has controls on the page and also controls inside a tab control.
I was hoping that by setting the tabindex values appropriately, the user could just tab from the controls outside of the tab control to the controls inside the first tab item, but it seems that the items inside tab control are skipped when tabbing around the form.
Is there a way to have the tabbing go into the tabitem/tab control?
WPF provides a number of ways to affect the tab order in an application. Probably the most important is also strangely the least known. I'm talking about the KeyboardNavigation class and in particular, the KeyboardNavigation.TabNavigation Attached Property. From the linked page on MSDN, this property Gets or sets the logical tab navigation behavior for the children of the element that this property is set on.
There are several possible values in the KeyboardNavigationMode Enumeration used that affect the tabbing order in different ways. Take a look at the last linked page to see which one suits your situation best, but as an example, the Local value has the effect that Tab Indexes are considered on local subtree only inside this container and ... [Navigation leaves the containing element when an edge is reached].
<Grid KeyboardNavigation.TabNavigation="Local">
...
</Grid>
This is a problem I've often faced and it's a tricky one. From my understanding, the reason that it doesn't work as you'd expect is because tab order (even specified via TabIndex) is contextual. TabIndex of higher level items will be prioritized over inner elements. So if you have two TabItems inside of a TabControl, and each one has UIElements inside of them, even if the TabIndex is specified, tabbing will first traverse the TabItems before it moves down to the contents of those controls. I "think", IIRC" this has to do with how the page is composed, but don't quote me on that. MS has weird reasons for some of these subtle nuances.
Onto the solution. What I've done in the past (so long as you're NOT working on WinRT, which makes this problem even worse) you can use UIElement.Focus. I store a list of UIElements in the order I wish them to be when tabbed in the code. Then, by binding the KeyDown event to a common handler for all of these controls, I do something like this:
int currentIndex = TabbableControls.IndexOf(sender);
UIElement next = TabbableControls[(currentIndex + 1) % TabbableControls.Length];
next.Focus();
Hope this helps!
Here is interface that I want to achieve:
Basically, this is 1 level deep structure with folders and files inside folders.
Screenshot that you see is my attempt doing this with ItemsControl and ListBox inside ItemsControl
Things that I need:
Folders not selectable. No interactions, just showing them.
Only one file can be "selected" at time
Files can be dragged and dropped from one folder to another
Everything done in MVVM
Right now with the way I do it - multiple ListBoxes therefore focus on multiple elements which is bad.
I don't know yet how to achieve drag/drop.
I'm thinking about TreeView control but unsure how is that going to work.
I'm looking at pointers on how to achieve this scenario.
One TreeView, two TreeViewItems styles "FolderLevelStyle" and "FileLevelStyle". Extract the defaukt style from Blend for both of them.
In "FolderLevelStyle", remove all triggers for IsMouseOver and IsSelected properties. Also, set ItemContainerStyle to be "FileLevelStyle".
This will give you points 1 and 2.
[in "FolderLevelStyle"] You can also set IsExpanded to True and collapse the ToggleButton in the control template (including removing all triggers that affect that button) - this will not allow the user to "close" folders.
Regarding Drag-And-Drop, there are several approaches to this. Start here. See how you can integrate it into your MVVM schema. I'd gravitate towards creating a Behavior (or attached behavior) that will be set on the root panel in the DataTemplate for the file item.
My requirement is rather a tricky one (it seems to me).
I will explain the scenario.
I have a DataGrid. In the DataGrid, I have two columns in which I have a grid in every cell of these two columns, inside of which, there are two comboboxes - the purpose being to switch the visibility based on some conditions.
When we select a value in the combobox, the combobox itself, plus some other controls in some other columns will get disabled (requirement of the pjt). Now there is also, another requirement like, Tab should not be allowed in the cell which has disabled controls - say disabled combobox.
We are setting the controls as Enabled or Disabled based on a selected value from the combobox. So, since we are applying the disabling property on the control level, and the IsTabStop property is on the cell level, I am not able to restrict Tabbing in the cells having disabled control.
Any thoughts?
Don't use a DataGrid.
DataGrid's are awesome for read-only stuff, but they seem to suck for doing any kind of interesting editing. After well over a week of fighting with it, I've given up on it.
Right now I'm looking for a replacement, which may end up just being a scrollable stack panel with manually added controls.
WPF: Is there a "ListBox" without the ability to select items?
I have a silverlight control that has a few element such as: Image, TextBox and a TextBlock.
The application shows a list of the same control and the controls are placed in a specific layout, in grid with rows and cols.
Now,
I would like to be able to modify all the controls layout and arrange the element differently (preferred animatedly) without reloading the control.
Does anyone know how to do so?
Thanks,
Ronny
Use the States pane in
Expression Blend 3 to define different
layouts.
Use the GoToStateAction for the objects/events that you want to trigger the change or call VisualStateManager:GoToState(this, "NewState", true) from your code behind to switch layouts.
Use FluidLayout (the wave-shaped first button first for the State Group) to animate the change from one grid col/row to another.
This is using winforms.
I have a listbox and a combo box, both tied to the same datasource, same display members, same value members. All is bound just fine and the items show up in both the controls.
The problem is when I change a selection in one control, it moves to the same index in the other control. I don't have any events tied to either control. It is just happening on its own. Has anyone ever run into this?
This is because both the controls share the same BindingContext/CurrencyManager. Controls inherit the BindingContext from their container control. A BindingContext maintains only one CurrencyManager per DataSource. If you want to have two different CurrencyManagers, you need to have two BindingContexts.
So when once of the controls selection is changed, currencyManagaer.Current gets updated. This affects all the controls that share the same DataSource.
Instantiate a new BindingContext and assign it to the BindingContext property of one of the ComboBoxes:
comboBox2.BindingContext = new BindingContext();
This should solve the problem.
The datasource is a separate object. When one of the controls changes the datasource active row it sends out an update notification to the other controls to move accordingly. This is normal and expected behavior.
The idea behind it is to simplify navigating record sets while keeping all the bound controls in sync.
If you don't want that, use two datasources tied to the same underlying data.
I think that might be intended to be a feature. For Master/Detail type forms.