Measure Control with double.PositiveInfinity WPF -
Measure Control with double.PositiveInfinity WPF -
i working on custom command has custom panel , within custom panel have little , simple measureoverride
method passes size of double.positiveinfinity
children measureoverride
method. custom panel should take care of layout , should create children bigger or smaller depending on window size.
if have dealt controls should know how wpf layout scheme works , every kid calls measureoverride calls measureoverride of childs children , on.
now problem when resize window, custom panel receive flag measure 1 time again hence measureoverride
called 1 time again time while passing double.positiveinfitinty
size children, children measureoverride
doesn't called @ (but method should called according definition of wpf layout system). why so? thought when phone call measureoverride
on parent children forced measure.
obviously wrong explain me how control/child know when measure again?
by way passing size of double.positiveinfinity
children tell them take much space needed.
code:
protected override size measureoverride(size availablesize) { double x; double y; var children = this.internalchildren; (int = 0; < children.count; i++) { uielement kid = children[i]; child.measure(new size(double.positiveinfinity, double.positiveinfinity); y += child.desiredsize.height; x = math.max(x, child.desiredsize.width); } homecoming new size(x, y); }
code simple. dont why children doesnt measured again. , sorry if have misspelled in code.
your children won't measured 1 time again because don't have to: since maintain passing same size, wpf knows there no reason measure 1 time again since resulting desiredsize
same.
that beingness said, desiredsize
updated measure
size kid considers appropriate. should take business relationship when overriding arrangeoverride
, have no obligation to: arrange children way like, fact measureoverride
called or not children should irrelevant.
wpf wpf-controls measureoverride
Comments
Post a Comment