.net - Auto-sizing elements based on layout position -


basically want lay out visual elements can change content according location laid. want in wpf might able suggest general algorithm without knowing wpf.

example: consider wrappanel contains labels hold text. when label laid wrappanel @ beginning of new row leading white spaces removed text. indeed make label shorter.

the think knows such label laid wrapppanel layouting. 1 approach code custom panel overrides measureoverride , arrangeoverride , change labels inside measureoverride before calling measure on label. don't because:

  1. it ugly hack (panel , measureoverride , arrangeoveride should position children not change them).
  2. i'm not sure think if changed label inside measureoverride label cause layout updated in response lead (recursive) call measureoverride (=> infinite loop).

so please suggest right design scenario. how should this? 1 comes mind to:

  1. have regular wrappanel.
  2. every times width or height changed or children changed (its children might repositioned) update children before measureoverride , arrangeoverride called.
  3. during process of updating children (2.) no call measure or arrange of wrappanel can made. question: how temporally inhibit such calls ?

before suggest use richtextbox or textblock deal white space @ beginning of lines note labels , white spaces example - little more complicated. if know how solve 'labels , white spaces' correctly i'll know how solve real problem too.

if want know why need have on question create guitar chords editor in wpf , h.b.'s answer.


Comments