Prevent the ItemsControl from changing the focus when clicked (Silverlight) - silverlight

I have an ItemsControl that host some input controls (textboxes, etc). When I click in the background of the ItemsControl, the focus is automatically changed to the first item in the ItemsControl.
Is there a way to prevent this? I already tried overriding OnGotFocus on the ItemsControl without calling base but it did not worked.
Thanks in advanced!
Jacques.

Ok, I figured out what was causing the first element to get the focus. In my case, I am using a ScrollViewer hosting a custom ItemsControl. The ItemsControl and container inside of it have IsTabStop set to false. The change of focus is made by the ScrollViewer in the OnMouseLeftButtonDown method.
Since the ScrollViewer is sealed, I had to override the OnMouseLeftButtonDown on my container and ItemsControl to set e.Handled to true. This solved my issue.

Related

Skip KeyboardNavigation for all Controls in a Panel or Grid in WPF

Normaly KeyboardFocus will be skipped, when the controls IsTabStop property is set to false. But there is no such porperty for the Grid or other Panels. I tried the Attached Property KeybordNavigation.IsTabStop, but this neither had the affect of skipping the Keyboard Focus for the hole grid.
I want to skip all controls within a grid when one of the grid descendant controls will normaly reseive the focus. Has somebody experience with this an can provide an solution?
You were close. On your Grid you need to use the attached property:
KeyboardNavigation.TabNavigation="None"

WPF TabControl - In need of a default message before tabs load

I have a WPF TabControl who's TabItems are MEF'd in at run time. However, they are MEF'd in only when a certain item in a left-hand treeview is selected. What I'd like to do is display a centered message inside the TabControl indicating "No Active Scenario Selected". I tried adding a TextBlock inside the TabControl but what I got was a TabItem instead. Any ideas?
One way to do this is simply by putting a TextBlock on top of the TabControl and show it when the TabControl doesn't have any Tabs added.
You can bind the Visibility of the TextBlock to the HasItems property of the TabControl and use a value converter (BooleanToVisibilityConverter or your own implementation) to show and hide the TextBlock.

Tooltip for disabled TabItem

I'm wanting to have a tooltip for disabled TabItems in a TabControl. The standard way of putting tooltips onto disabled controls in Silverlight is by wrapping the control in a dummy element that has the tooltip, but I can't get at the TabItem like that. The TabItems' host control is a TabPanel, which doesn't seem to expose any useful properties.
Any ideas?
I had the same problem with putting a Toolip on a disabled menu item, i solved it by changing the VisualState of my menu item to Disabled and then disabling the MouseButton events.
VisualStateManager.GoToState(tabitem, "Disabled", true);
You'll have to be careful with other events though, because the VisualState will change according to different events. It's not a perfect solution, but it will work for certain scenarios.
Hope this helps
My current workaround for my own problem:
I've got a TabControl Behavior that finds the "TabPanelTop" template part (or left, right, or bottom depending on TabStripPlacement), along with the "TemplateTop". I add a Canvas into the TemplateTop (which is a Grid), and fill it with Transparent Rectangles whose positions (using TransformToVisual) and sizes are calculated (and updated) to be the same as the TabItems, which are the children of the TabPanelTop.
The visibility of the Rectangles is bound to the inverse of TabItem IsEnabled, and the ToolTipService.ToolTip is bound to the ToolTipService.ToolTip on the TabItem.
It's a bit scary but it works and is easy to use.

WindowsFormsHost content doesn't show when its given to a ContentPresenter

I have WinForm controls I want to put in a WPF DropDownButtons(Extended WPF Toolkit) DropDownContent. Putting the controls to a WindowsFormsHost and that one is giving to the DropDownContent doesn't work.
The Winforms control doesn't visible. In the template the DropDownContent property is a ContentPresenter.
If I want to try this whole story with a common container (StackPanel, Grid, etc.) it works fine.
Does anybody know how can I solve this?
The DropDownButton has a Popup whose AllowsTransparency is set to true - see the template here. You cannot put a WindowsFormsHost into a Popup whose AllowsTransparency is true. You'll have to modify the template for the DropDownButton so that its AllowsTransparency is false.

Cant Drag ListBoxItem Adorner outside of ListBox in WPF -ScrollViewerProblem

I am working with a WPF application that uses alot of drag and drop. Everything is working fine, with exception of ListBoxItems. I have a ListBox with ListBoxItems that can be dragged to another target( a StackPanel). The problem is, when I drag the cursor outside the ListBox, I cant see the Adorner that I have setup with the ListBoxItem?
I know this is a common problem, but I am just not sure how to fix it. Is there something that I need to do to allow me to drag outside of the ListBox control?
Below I have attached what the UI looks like so far. As you can see, there is a ListBox on the bottom left. When I drag an item, the adorner appears, and follows the cursor around while the cursor is over the ListBox, but if I try to move the cursor away from the listbox, the Adorner seems to almost go under the other controls(zIndex?).
Edit - Solution
I have changed the code to handle the AdornerLayer relative to the window as oppose to relative to the AdornedElement
So I changed
layer = AdornerLayer.GetAdornerLayer(_originalElement);
to
layer = AdornerLayer.GetAdornerLayer(this);
This solved the problem of the ScrollViwer clipping the AdornerLayer
The ListBox (or, to be specific, the ScrollViewer within the listbox) clips any adorners attached to it's children. This is done to ensure that adorners for items scrolled out of view are not shown. To get around this, you need to explicitly put thing in the Window's adorner and not that of the listbox or listboxitem

Resources