1

I have two related problems that occur in the following situation.

I have a winforms window that contains some panels. In a few of these panels there are a number of (custom) wpf user-controls.

1

if i check .Visible on the elementhost it always returns true. even though I can see that its not visible.

2

if i check .Height it will always give me the same size. even though the control itself shows a variable number of things and changes size acordingly (through Visibility.collaps);

how can I get to the correct values?

edit: code added

Okey Now I'm officialy going crazy. If I add a few messageboxes in my code to check when and in what order the above code gets executed. When I do this everything works! but as soon as I delete the messageboxes it reverses the effect. Instead of getting bigger when needed it gets smaller en vice versa.... wtf wpf!

private Size bereken_panel(Panel P)
    {
        Size Sz = new Size();
        int tmp_H = 42;
        foreach (Control SC in P.Controls)
        {
            if (SC is SplitContainer)
            {
                if (SC.Visible)
                {
                    tmp_H += SC.Height;
                }
            }
            else if (SC is System.Windows.Forms.Integration.ElementHost)
            {
                if ((SC as System.Windows.Forms.Integration.ElementHost).Child.Visibility == System.Windows.Visibility.Visible)
                {
                    tmp_H += (int)(SC as System.Windows.Forms.Integration.ElementHost).Child.RenderSize.Height;
                }
            }
        }
       // tmp_H = 42 + n_showed * 25;
        if (tmp_H < 65)
        {
            tmp_H = 65;
        }
        Sz.Height = tmp_H;
        Sz.Width = 432;
        return Sz;
    }

so this is after some extra modification to clarify where the TopLeft point is.

 int p_x_links = panel1.Width / 2 - 436;
        int p_x_rechts = panel1.Width / 2 + 4;
        //links
        p_contact_gegevens.Size = bereken_panel(p_contact_gegevens);
        p_telnrs.Location = new Point(p_x_links, p_contact_gegevens.Size.Height + p_contact_gegevens.Location.Y + 8);
        p_telnrs.Size = bereken_panel(p_telnrs);
        p_bezoekadres.Location = new Point(p_x_links, p_telnrs.Size.Height + p_telnrs.Location.Y + 8);
        p_bezoekadres.Size = bereken_panel(p_bezoekadres);
        //rechts
        p_administratie.Size = bereken_panel(p_administratie);
        p_postadres.Location = new Point(p_x_rechts, p_administratie.Size.Height + p_administratie.Location.Y + 8);
        p_postadres.Size = bereken_panel(p_postadres);
Community
  • 1
  • 1
Daanvl
  • 608
  • 1
  • 9
  • 24

1 Answers1

0
  1. Most probabbly the control is overlapped by some other control. Visibility property in this case can be even True.
  2. Try to use ActualWidth instead.

EDIT

Sorry, the example is on ActualWidth, but you are asking for Height. Concept is the same btw.

Community
  • 1
  • 1
Tigran
  • 61,654
  • 8
  • 86
  • 123
  • ActualHeight is the same as RenderSize.Height? and Height is the same desiredsize correct? – Daanvl Nov 24 '11 at 11:31
  • so no changes in height. but the controls are not overlapping but side to side – Daanvl Nov 24 '11 at 11:45
  • @Daanvl: Where is TopLeft point of the Panel (assuming that size is calculated correctly)? – Tigran Nov 24 '11 at 11:57
  • @Daanvl: I still see use of Height in calculations, instead of ActualHeight. Try to user real redered size and see if it helps you. – Tigran Nov 24 '11 at 12:13
  • I can only use that in wpf. the form is winforms so there is only the Height property and nothing else. When there's a wpf element I Use RenderdSize.Height. I don't understand where else I should be using ActualHeight(even the elementhost doesnt have ActualHeight) – Daanvl Nov 24 '11 at 12:18