3

Updated problem:

In WPF I use a GridView (inside a ListView) to display a list of Textbox-Slider pairs. Each such pair is arranged in exactly one cell of the single column (by using a DockPanel for each pair).

The Slider has a minimal width so that it does not collapse, the textbox does not, it is resized dynamically on receiving input.

The problem is that when the textbox's width increases the column width is not equivalently changed. This causes the slider in the corresponding row to be visually clipped on the right side. As a result the slider's knob disappears in the void when moved to the right end.

So the question is: How do I force the column width of the gridview to resize dynamically if the contents exceed the available space (which was set at initialization time)?

Percentage sliders with disappearing knobs

Just ignore the label between the textbox and the slider (without it the behaviour does not change).

Bastian
  • 4,638
  • 6
  • 36
  • 55
  • 3
    If you have complex code the very first thing you should do is extract your problem area and post a self-contained example exhibiting the problem. Maybe you even solve the problem in the process. – H.B. Aug 30 '12 at 19:01
  • This is not a standard behavior. Which suggests that your containers (grids, stackpanels, dockpanels) are not setup properly. Strip that piece of code, so we can examine. – LadderLogic Aug 30 '12 at 19:31
  • It is difficult to extract the relevant piece of code as it is embedded in a quite complex program. – Bastian Sep 13 '12 at 17:30
  • Did you test this on several, different machines? – Emond Sep 14 '12 at 14:48
  • No, I don't have my working environment set up at any different computer than my working computer. – Bastian Sep 14 '12 at 14:55
  • 1
    "It is difficult to extract the relevant piece of code" Then just try to reproduce it with a simple reproduction of those three controls in a dockpanel. The burden of work should be on the asker, not the answerers. – N_A Sep 14 '12 at 15:11
  • What happens if you use a Grid instead of a DockPanel? – H.B. Oct 11 '12 at 11:30
  • @H.B. Unfortunately nothing, the problem just remains. – Bastian Nov 07 '12 at 13:05
  • Please refer the following link http://stackoverflow.com/a/15744968/1333423 – user1333423 Apr 01 '13 at 14:12

3 Answers3

2

one way to do it is to take the event of the label and buble it to the grid (sizeChanged) and then resize de grid in proportion to the lable size...

Mihai
  • 518
  • 4
  • 12
1

Some container probably clips it via ClipToBounds, or depending on how your background colors are implemented they may overlay from another column.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • After extracting the code to a clean new project I found out that it is not caused by `ClipToBounds`. Have a look at the updated post. – Bastian Oct 02 '12 at 10:07
1
Size containerSize=new Size(100, 100);
public Size CalculateSize(FrameworkElement visualBlock, Size containerSize)
{
    visualBlock.Measure(containerSize);
    return visualBlock.DesiredSize;
}

This code gets size of framework element for render inside container. After that you can set size programatically. Need to know parent size for correct work.

Bastian
  • 4,638
  • 6
  • 36
  • 55
Frank59
  • 3,141
  • 4
  • 31
  • 53
  • Well, in order to measure the size of a FrameworkElement I first need to have access to this element. The problem is, that the elements (namely the sliders) are inserted into the GridViewColumn. So I would have to access them from there - is there any method to accomplish that? – Bastian Nov 07 '12 at 14:07
  • try to use examples from http://stackoverflow.com/questions/636383/wpf-ways-to-find-controls – Frank59 Nov 09 '12 at 07:06