Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Measure Dilemma - Invalidate Measure On Elements Across VisualTree

$
0
0

Hi,

I am working on a Demo and I seem not to understand measuring and arranging completely in depth. I read alot about it hence I think I am not a newbie at understanding of measureoverride and arrangeoverride but something is still missing. 

The Demo is based on a big custom control called "CustomControl1" and few little custom control nested in "CustomControl1".  Inside "CustomControl1" I have my MeasureOverride and ArrangeOverride logic. The "CustomControl1" creates a visual tree that looks like this or better said the Template of "CustomControl1" is this:

<CustomControl1>   <Grid><CustomControl2 x:Name="PART_CC2"><Grid><RadioButton><CustomControl3></RadioButton></Grid></Grid></CustomControl1>

As I already mentioned the little custom controls are nested inside the big one and those little are "CustomControl2" and "CustomControl3". 

If you wondering why would I choose this complicated Template for "CustomControl1", then allow me to explain you what is the problem.

Inside my "CustomControl1" which is at the top as you can see I have an instance of "PART_CC2". PART_CC2 is a "CustomControl2". When I inside MeasureOverride of "CustomControl1" I call InvalidateMeasure method on "PART_CC2".

Here is code to understand better:

public class CustomControl1 : ContentControl
{
  CustomControl2 cc2;

  override OnApplyTemplate(..)
  {
    cc2 = this.GetChildTemplate("PART_CC2") as CustomControl2;
    ...
  }

  override MeasureOverride(..)
  {
    cc2.InvalidateMeasure();
    ...
    ...  //Here is some custom bla bla logic
    ... 
    for(int i = 0; i < ....)
    {
       child.Measure(double.PositiveInfinity, double.PositiveInfinity);
       ...
       ...  // Here is also some custom blah blah logic such as x = Math.Max(x, child.DesizSize.Width);
       ...
    }
    ...
    ...
  }

  override ArrangeOverride(..)
  {
    ..
  }
}

As you can see I have an instance of "CustomControl2" inside of "CustomControl1" and when I am in MeasureOverride method I call PART_CC2.InvalidateMeasure();

Now what is the problem there? The problem is when I loadt the window or I change the size the window. The measure process starts from MainWindow and it get to "CustomControl1", it even gets to MeasureOverride method of "CustomControl1", futhermore it even executes the PART_CC2.InvalidateMeasure() but then, thats it. Then "CustomControl2"/PART_CC2 doesnt get re-measured. Instead of re-measuing "CostomControl2" WPF thinks its done with measuring and starts to arrange. That shouldn't happen.

Why can't WPF do all the measuring first and then arranging? Why is PART_CC2 not re-measured even though I call InvalidateMeasure(). 

Does it have something to do with double.PositiveInfinity or with the <Grid> which is between "CustomControl1" and "CustomControl2"?






Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>