Can we overlay a WPF element by another? - wpf

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.

Related

WPF slider behaving like combobox

I need a control where user can pick only one option. Combobox is fine, radiobuttons are ok, but for some purpose I think about another crazy, but interesting solution.
There should be a slider control on a window and three possible positions of this sliding thing. I know this can be easily accomplished by setting slider's Minimum and Maximum plus TickFrequency and IsSnapToTickEnabled properties.
Now, is there a way how to add labels on left/right edge and center of slider showing user options within the slider? Or is it neccessary place labels/textblock below?
Last, though the most important thing is, how to associate integer slider positions with string options? I thought about switch, but this is wpf - there is "more wpf" solution, isn't it?
Just drag slider's rider to it's position and by binding set class string property to appropriate value.
Every control within WPF can have its visuals completely modified to suit your needs. This was/is the beauty of WPF over WinForms.
Can your slider have a TextBlock within it? Absolutely. Style as you desire and be on your way. A great article can be found via MSDN Magazine which outlines the approach to customizing WPF controls.
With regard to the integer values, use an IVauleConverter to translate the values to whatever you prefer.

Is it possible for WinForm controls (Panel,etc.) to grow like a webform control?

I'm converting an app from ASP.NET WebForms to WinForms. There is one asp.net page which contains a ListView/Repeater that contains several custom controls, which in turn contain a ListView with other custom controls. Basically the layout looks like a TreeView, but on each node/leaf there are few controls like comboboxes, etc.
When this is in ASP.NET, the page automatically lays itself out, so it is several screens tall - if I add 20 buttons into a Panel, it will grow and the browser will get scrollbars.
I'd like to do the same thing in a WinForms application - so I'll have a user control that will contain a lot of controls in a some variation of Panel (Flow, Table layout), and the controls might have another controls inside them, etc.
The problem is, that when I make winforms app, each control has specific height in the design time. I'd like some user controls to be able to grow with their contents - so they'll add up. In the main Form, there should be a vertical scrollbar, just like in the web browser when the generated page is taller than the screen.
I'd just like to get some general pointers in the right direction. Thanks.
Use Anchor and Dock container properties.
Yes, to expound on Anchor and Dock...try this
-Place a Panel on an empty form, and set its dock property to Top
-place a textbox in the panel, and Dock it to Full...it should fill the whole top panel
-Place a splitter on the form, and if not already docked correctly, set its dock to top
-place another panel below the splitter, and set its Dock to Fill
-place another textbox inside the lower panel and fill it as as well
Now you have a form with two resiable textboxes and will resize when the form does.
*you may have to set the textbox MultiLine property to true but not sure.
Hope this helps.
Anchor the controls to the parent. Anchoring all four sides will cause it to stretch.
If the Anchoring and Docking answers don't work for you, there is another option. It's not pretty, but you can access a control's properties and change them dynamically during runtime. You'd do something like: if(listBox.Items.Count > [yourVal]) listBox.height = [yourFormula] or something.
It's been a while since I've done a Win Form (and I don't have my IDE fired up at the moment) but I'm pretty sure there's even a ScrollPanel or other scrolling control that you can set on your form.
That said, when you're working with WinForms, the less scrolling you can make your users do, the better.

WinForm Panel scrolling without a scrollbar?

I'm creating a User Control that's basically a Panel (with random content inside), and I need to be able to scroll up and down this Panel using buttons (up and down) rather than the scrollbar.
The reason I have to do it this way is because the program will be used on a touch screen monitor and we need big buttons rather than an ugly little scrollbar.
I've been messing around with the VerticalScrollbar properties, and none of them seem to do anything. I've noticed that if I set AutoScroll to false, AutoScrollPosition actually shows coordinates, except negative of what it should be. Also, I've noticed that panel.VerticalScrollbar.Visible = true; only seems to work when placed outside of the constructor. Is there a reason for that?
Basically, WinForms' scrollbars are very confusing (buggy?) to me. Does anyone know a good way to scroll up and down a panel programmatically with buttons (I don't care if I need to have an invisible scrollbar).
Thank you! =D
Make your UserControl a regular UserControl (i.e inherit from UserControl instead of Panel) and place a Panel on your UserControl. Put any content/controls on the inner Panel, and then change the Panel's Left and Top properties to move it around without scrollbars. You could also add buttons to your UserControl to handle the movement of the inner Panel.
A simpler way, however, might be to just use really wide/high scrollbars, and set their Thumbwidth (I think this is the property) to the same large value - this will produce scrollbars that are easy to use with the fingers. To my knowledge there's no way to do this with the scrollbars that appear on a Panel with Autoscroll set to True, so you'd still need to use the method I mentioned above (with an inner Panel sitting on your UserControl) and add the scrollbars to move it yourself.
I agree that scrollbars in Windows suck, so while I'm normally in favor of just using the standard controls that everyone is used to, I don't see anything wrong with rolling your own in this case.

WPF page layout control selection

I have an imagebrush of a soccer field as the page background and I want to be able create a line up by dragging players off the bench and positioning them on the field accordingly. I don't know what control to use for the background that allows the PlayerCard control to reside where it is dragged. Any help as to how to begin would be appreciated.
You can get the idea here.
What control to use?
I believe you want the Canvas container control. It lets you arbitrarily place child controls with a Left and Top attached property, similar to the way Windows Forms does it.

WPF tooltip virtualization

Is there any way to virtualize tooltip in WPF? I have many dataitems displayed on map. When i'm changing template, for example, it takes a lot of time to generate UI for tooltips that are invisible. Maybe wpf supports something for such cind of virtualization?
Thanks in advance.
The way in which I've done this before is to generate a tooltip that is very simple, with a container item as the root and a simple single textblock inside, and then hook into the loaded event on the textblock, to detect when the tooltip is trying to be shown.
At that point, I then generate the full tooptip on the fly and replace the contents of the container, removing the textblock placeholder in the process.

Resources