Tooltip for disabled TabItem - silverlight

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.

Related

TabItem template based on TabControl.TabStripPlacement

The default template for TabItem, as defined here, assumes that the tab strip is at the top. If we change the TabStrip.TabStripPlacement to the right, left or bottom, the margins and border thicknesses don't make sense. How would someone go about changing these values based on the parent TabControl TabStripPlacement. This is for a style used in application resources not just for a specific instance of the control.
To answer my own question. I found out that there is actually a TabItem.TabStripPlacement that can be used on the control template triggers

Silverlight toolkit Expander doesn't expand when the size of its content changes

I have a silverlight expander control which wraps a grid. In the grid, I have a number of text boxes, combo boxes as well as some invisable (collapsed) text blocks. I also have an animation and when it is triggered the grid shows those hidden text blocks.
My problem is, when the hidden text blocks are shown after the animation is run, these text blocks push other controls down and because the expander doesn't resize itself, the controls at the bottom get pushed outside of the expander and become invisible.
I tried to call UpdateLayout() after the SizeChanged event of the grid but doesn't work.
Any suggestions on how to resolve this issue would be much appreciated!!
I actually have fixed this problem by myself. I discovered in the style of the expander control, a while ago I put an ExpandableContentControl instead of normal ContentControl because it has a nice animation when you expand/collpase it. But this control doesn't resize properly... (see http://silverlight.codeplex.com/workitem/4544?ProjectName=silverlight) I guess this is why the AccordionItem control is so buggy because it also has an ExpandableContentControl in it. As soon as I replaced the ExpandableContentControl with a normal ContentControl, the expander worked as expected. :)
The problems is because the expander always use the same width (or height), so you must recalculate the width of the grid by code and assign it to the columndefinition.

How do I create a WPF Dropdown panel

I'd like to create a dropdown panel in WPF the acts like a ComboBox/Expander hybrid. I'm currently using an Expander but it pushes the the controls underneath it down when it expands.
I simply want it to act like a ComboBox and overlay it's dropdown. I've looked at using Popups but they don't move with the underlying window when it's moved.
So, I've concluded that the closest control to my needs is a ComboBox which allows me to put a Grid or StackPanel into its dropdown area.
Any ideas how to achieve this?
I am not exactly sure what you want to do:
But the layout depends very much on the parent control. If your controls are in a Stackpanel all controls will be moved if a control expands or changes its size. If you use a Canvas you can align controls on top of each other.
Also Adorner are useful when you want overlay something above something else.
You can change the appearance of the ComboxBox and you can put a grid or anything else inside it. Have a closer look at ItemTemplate.

how can we change zindex of a silverlight control programmatically?

I have some controls added in a stackpanel programmatically. What i want to do is that i want one of the controls in this stackpanel to be placed over another control. Specifically, I want to place button over an image in this stack panel. I couldn't find zindex property in c# codebehind. Although it seems very simple problem but i am unable to find any clue to solve this problem. Anyone please......??
Try placing all your controls on Canvas. Then you can set Zindex with:
this.controlName.SetValue(Canvas.ZIndexProperty, 10d);
Only the Canvas panel supports a ZIndex property. Stackpanel doesn't because each item is placed one after the other in the panel so they shouldn't overlap each other. This can be a little annoying at times when you have animated transforms moving the items about because the previous assumption isn't actually true.
In general though if you need to place items in a visual stack the Stackpanel isn't the right place for it. Perhaps a Canvas or you could use a Grid where the oridinal position of a element determines its "zorder" in a cell.
From xaml:
<StackPanel Canvas.ZIndex="1">
</StackPanel>

Binding a Popup to another control's relative screen position

I'm writing an XBAP with a complex Popup (Canvas Z-index of 99 with a grid on it...) that I would like to "attach" to the button that opens it and follow that button around wherever it goes on the screen. For example, if the button is in a ListBox or an XamDataGrid I would like the popup to follow the button as it scrolls through. If it is beneath an Expander I want it to stay attached to the button when the expander forces it to move, etc.
Any Ideas?
When using a Popup, neither PlacementTarget nor CustomPopupPlacementCallback is used after the popup has originally appeared. So any use of these properties will not allow the popup to track the button as it moves.
Several ways occur to me of achieving what you desire:
Attach a custom Adorner to the button and put the popup inside it. Disadvantage: Popup is not connected to Button or surrounding elements, so it won't inherit properties & DataContext from them.
Attach a custom Adorner to the button. This adorner will get measure and arrange calls when the button moves relative to the AdornerLayer, allowing you to manually update the Popup position. As long as your AdornerDecorator doesn't move relative to your Window (eg if it is the direct child of the Window), you can easily detect the AdornerLayer being moved by monitoring changes to Window size. Disadvantage: Complex to code & get right.
Don't use a Popup at all. Instead wrap the button in a <Grid> alongside a <Canvas> with zero width and height and the desired position. Inside the <Canvas> add the UserControl for the popup with an appropriate ZIndex. It will extend past the edge f the Canvas, which is just fine in WPF. Instead of using a Popup control just control the visibility of the UserControl. Disadvantage: Will not really be totally on top of all other objects, can't extend off edge of window (may not be an issue for XBAP, though).
I'm not sure if it will auto-update for you or not, but the PlacementTarget property allows you to specify a control to position the popup relative to. If that doesn't work, then maybe CustomPopupPlacementCallback will do the trick?

Resources