c# - Content Binding only works for integers and Strings -


i new xaml , have work on existing project university. unfortunately confused how deal content binding. have following xaml code (snippet):

<!-- snapshotsv.xaml --> <s:scatterview grid.row="1" grid.column="1" grid.rowspan="2" panel.zindex="2" name="snapshotsscatterview" itemssource="{binding path=snapshotscollection}" allowdrop="false" background="#ff151515" width="{binding scrollcontainerwidth}">     <s:scatterview.itemcontainerstyle>         <style targettype="s:scatterviewitem">             <setter property="height" value="300"/>             <setter property="width" value="300"/>             <setter property="orientation" value="0"/>             <setter property="canscale" value="false"/>             <setter property="canmove" value="true" />             <setter property="canrotate" value="false" />             <setter property="center" value="{binding path=itemposition}" />         </style>     </s:scatterview.itemcontainerstyle>     <s:scatterview.itemtemplate>         <datatemplate>             <grid>                  <label content="{binding path=id}" />                 <image source="{binding path=snapshotimage}" />             </grid>         </datatemplate>     </s:scatterview.itemtemplate> </s:scatterview> 

the following view-model belongs view (snippet):

// snapshotsvm.cs public class snapshotsvm : viewmodelbase {     [...]      public observablecollection<snapshotitem> snapshotscollection     {         { return snapshotmaker.snapshotitemcollection; }     } } 

snapshotsitemcollection list having 1 or multiple snapshotitem-classes. implemented observablecollection<snapshotitem>. snapshotitem-class looks following:

public class snapshotitem : viewmodelbase {     private int _id;     private image _image;     private string _xmlstring;     private point _position;      public int id     {         { return _id; }     }      public string test { { return "abc"; } }      public image snapshotimage     {         { return _image; }     }      public string xmlstring     {         { return _xmlstring; }     }      public point itemposition     {         { return _position; }     }      public snapshotitem(int id, string snapshotdirectory)     {         this._id = id;         this._image = image.fromfile(snapshotdirectory + @"\snapshot-" + id + @".png");         this._xmlstring = null; //todo later         this._position = new point(id*400+200, 200);     } } 

so far good.

what not understand fact, content binding works datatypes. can see in snapshotitem class, there integer called id , string called test. work fine in xaml when bind them via {binding path=id} or {binding path=test}. other data properties such snapshotimage or itemposition not working.

i inspected variables in snapshotitem class via breakpoints. , correctly set in constructor. not understand why cannot use them content binding.

additionally have noticed works when create snapshotitems directly in snapshotsvm.cs file. created similar class there, filled random data , worked fine. code logic reasons want create snapshotitems in static snapshotmaker class. creation of elements work fine , can see them in gui. itemposition , snapshotimage cannot bound.

binding of scatterview (i.e. itemssource="{binding path=snapshotscollection}") happens when set snapshotscollection first time. therefore need initialize data (e.g. positions, images, etc) when you're creating collection. should this:

snapshotscollection = new observablecollection<snapshotitem>();  int id = 1; var point = new point(800,200); var image = image.fromfile(snapshotdirectory + @"\snapshot-" + id + @".png"); snapshotscollection.add(snapshotmaker.create(1, point, image)); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -