how can we change zindex of a silverlight control programmatically? - silverlight

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>

Related

WPF Adorner Overlay Problem

I am trying to achieve functionality similar to that of a Popup, without using a Popup, but instead adorning my ContentControl with a basic adorner. Basically, I want the ContentControl to have an "overlay" effect, whereby it is the topmost object, above all other elements - similiar to that of the Popup control.
Here is the problem that I am running into, and I am hoping that someone can point out where I am going wrong:
I have a stand grid with two row definitions. The first row contains a UI element - for example, a rectangle. The second row contains a custom control that I have developed to emulate the functionality of a "drawer" sliding out. Basically, when I click on button, I am going to animate a TranslateTransform to "slide" my ContentControl "up". This works fine - except that it gets cropped underneath the rectange in the first row of the grid. If I remove the row definitions in the grid, then when the desired behavior is achieved - the ContentControl is moved "up" and partially "on top" of the rectangle. The rectangle is merely a place holder for what I am trying to achieve. I basically want to have a drawer type control that can slide out and be on top of all other controls.
I am somewhat new to using the Adorner class, so, I am hoping that someone can please point out where I am going wrong.
Thanks.
Chris
Change the parent of the adorner to the full grid, and not just your control. If you put a control in a grid row, and set the adorner to adorn the control, it will usually be clipped to that row because the control is.

Can we overlay a WPF element by another?

I've this situation:
A label placed in Footer Cell of a RadGridView doesn't have sufficient width available in its container for displaying its full text.
Is it possible by any ways to have the label cross its container boundaries and show full text?
Thanks!
The space given to any element depends on the parent control or Panel that contains it, as well as its Width, Height, Horizontal and VerticalAlignment, and Margin. Normally you can manipulate some combination of these directly to change overlapping behavior but by using a DataGrid control you've given up a lot of that control since things like ColumnSpan are set up by the control internally. You could try setting negative Margin values and changing the Panel.ZIndex but I doubt those will help.
The best solution I can recommend without more detail is to use TextWrapping or TextTrimming to avoid ugly clipping, maybe in combination with a ToolTip showing the full text.
You can overlay any WPF element by another anytime. Only place where it fails is the WebBrowser control .The WPF WebBrowser has not been improved a single bit from WinForms WebBrowser. It is still the same simple activex control. However, you can bypass even that with a tooltip control.
I believe you can either set ClipToBounds=False to allow it to expand outside its area, or set TextWrapping=Wrap to allow the text to wrap.
EDIT: Forgot ClipToBounds is only honored in the Canvas control, so wrap your label in a Canvas and set ClipToBounds=False and it should work.

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.

Listbox styling and control template issue in silverlight

I have to change Listbox's control templated in a way that it can look like below image
alt text http://www.freeimagehosting.net/uploads/05598e4d35.png
i have added togglebutton in listboxdatatemplate...
have one stackpanel in listbox style template...
so structure is like
border - stackpanel - grid - itemcontainer[boder-togglerbutton]
now to make first and last item curved... what are the ways...
if i make stackpanel border curved... when firstitem is selected and its background is changed... it shows a square inside outer border... so i am not able to get look showed below...
any idea?? how to get design done in the way with listbox tht can be showed like image above...
in image 1,3 and 4 items are selected and others are in normal mode...
-thanks in advance
I did it with a listbox in Blend inside of the ItemTemplate by creating a leftBorder and a right Border that are in the same space. The leftBorder is defined with cornerRadius 10,0,0,10 and the right with cornerRadius 0,10,10,0. I then set them both to opacity 0 (you can use visibility if you prefer) and set a ChangePropertyAction on both of thier loaded events conditional on the first and last item in your list.
That is the bad part, I did need to do it conditional on the items in your list but you could define another property and set that to first and last or create multiple templates that you set if there are no more items in the list from the control (not in the template).
If you think this may be interesting to you, let me know and I will post on my blog as well as try to make a couple of adjustments for your situation. I am not sure how to upload a project to here.

Using RenderTransform to increase the size of a DataTemplate in WPF

I'm using a DataTemplate that animates a RenderTransform to increase its size when the mouse is over it. The problem I'm having is that when the animation is in effect the enlarged list box item appears behind other items. Is there a way to control the ZIndex of the list box item from within my DataTemplate so that it's always on top of other items?
You can set the Templated Element's ZIndex from template using Triggers. Find out the templated parent control by VisualTree parsing like bellow
{RelativeSource FindAncestor,AncestorType=...
The zIndex is only available on elements hosted inside a Canvas. Therefore you may be able to wrap the whole listbox control in a canvas then set Canvas.zIndex to 99 as part of the Trigger you are using to do the transform . However I could not get this to work.
The only other option that did work is to use a LayoutTransform rather than a RenderTransform as this will move the other items out of the way as the transform is calculated before the items are placed. This would mean there would be no need to set any zIndex, however it would depend on your requirements.

Resources