c# - DependencyProperty does not trigger LayoutProcess -


i writing own panel (wpf) draw model. have model-dependencyproperty , want changes model affect layoutprocess.

modelproperty = dependencyproperty.register("model", typeof(model), typeof(modelpanel),             new frameworkpropertymetadata(null, frameworkpropertymetadataoptions.affectsmeasure)); 

how should implement model-class changes affect layoutprocess? i've tried inotifypropertychanged. didn't work.

sorry this, think might going wrong way.

in wpf panel supposed define how things laid out.

  • a stackpanel places things 1 after another, horizontally or vertically.
  • a wrappanel lays things out in row/column wraps next.
  • a canvas lets position things @ x,y points.

since attempting use panel, assume have collection of things in model. can handle collection listbox can give correct panel type to. i.e.

<listbox itemssource="{binding mythings}">     <listbox.itemspanel>         <stackpanel orientation="vertical"/>     </listbox.itemspanel> </listbox> 

however commonly gives list of class names, each 1 representing 1 of things, need tell wpf how display it, , use datatemplate. can define these in many places, in resources section (for control, window or application) or need it.

<listbox itemssource="{binding mythings}">     <listbox.itemspanel>         <stackpanel orientation="vertical"/>     </listbox.itemspanel>     <listbox.itemtemplate>         <datatemplate>             <textblock text="{binding name}"/> <!-- assuming each thing has name property-->         </datatemplate>     </listbox.itemtemplate> </listbox> 

update: or if have different types of items show

<listbox itemssource="{binding mythings}">     <listbox.itemspanel>         <canvas/>     </listbox.itemspanel>     <listbox.resources>         <datatemplate targettype="{x:type myline}">             <line x1="{binding left}" x2="{binding right}"                    y1="{binding top}" y2="{binding bottom}"/>         </datatemplate>         <datatemplate targettype="{x:type myrectangle}">             <border canvas.left="{binding left}" canvas.right="{binding right}"                      canvas.top="{binding top}" canvas.bottom="{binding bottom}"/>         </datatemplate>             </listbox.resources> </listbox> 

also have read through josh smith's article on mvvm, has lot of examples , practice in there, , introduce pattern keeps models cleaner.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -