c# - Binding property of usercontrol to data -


i'm not sure of correct terminology use. created windows store app year ago , main page created visual studio , never changed much. uses view model works fine don't know enough fix problems. anyhow...

the page uses gridview display contents of collectionviewsource element reference observablecollection. works fine. datatemplate 1 of data items looks right now:

<datatemplate x:key="topimagetiletemplate">     <grid minheight="135" width="350" margin="0" background="transparent">         <grid.rowdefinitions>             <rowdefinition height="auto"/>             <rowdefinition height="135"/>         </grid.rowdefinitions>          <textblock text="{binding path=imagepath}" fontsize="33"/>          <usercontrols:waitingimagecontrol sourcepath="{binding path=imagepath}" grid.row="0" width="350" height="165" horizontalalignment="center" verticalalignment="stretch" automationproperties.name="{binding title}" visibility="{binding typedescription, relativesource={relativesource mode=templatedparent}, converter={staticresource texttovis}}"/>          <usercontrols:waitingimagecontrol sourcepath="xxx" grid.row="0" width="350" height="165" horizontalalignment="center" verticalalignment="stretch" automationproperties.name="{binding title}" visibility="{binding typedescription, relativesource={relativesource mode=templatedparent}, converter={staticresource texttovis}}"/>          <progressring opacity="0.5" foreground="#ff8a57ff" grid.row="0" name="theprogresscontrol" isactive="true" height="32" width="32" background="transparent" verticalalignment="center" horizontalalignment="center"/>          ...      </grid> </datatemplate> 

the problem have data item contains string called imagepath want pass waitingimagecontrol usercontrol , it's not working. textblock works fine , text displays imagepath string fine. second waitingimagecontrol works fine , code handle sourcepath passed "xxx" fine too. first waitingimagecontrol never gets passed imagepath value data item.

this sort of binding issue , know little binding i'm sure try (or show in question). given textblock binding works , second waitingimagecontrol binding works, i'm @ loss.

here's waitingimagecontrol code sourcepath property:

    public static readonly dependencyproperty sourcepathproperty =          dependencyproperty.register("sourcepath", typeof(string), typeof(waitingimagecontrol), new propertymetadata(""));      public string sourcepath     {         { return m_sourcepath; }         set          {             if( string.isnullorempty( value ) )                 return;              m_sourcepath = value;             resourcesstore store = new resourcesstore();             if( store.count() == 0 )             {                 var ignoreme = coreapplication.mainview.corewindow.dispatcher.runasync( coredispatcherpriority.normal, () =>                 {                     // no progress , no image...                     theprogresscontrol.visibility = visibility.collapsed;                     theimage.visibility = visibility.collapsed;                 } );                 return;             }             resourceitem item = store.getitembyfilename( m_sourcepath );              localinboxservice.instance.inboxstatuschanged -= inboxstatuschanged;             inboxstatuschanged( null );             localinboxservice.instance.inboxstatuschanged += inboxstatuschanged;         }     } 

the code supposed show image element , hide progressring element when image has been downloaded.

and code data item, again, works fine when imagepath passed automatically textblock:

    public string imagepath     {                 {              return this._imagepath;         }          set         {             this._imagepath = value;             this.setproperty(ref this._imagepath, value);        }     } 

any appreciated making imagepath sourcepath binding (below) work:

    <usercontrols:waitingimagecontrol sourcepath="{binding path=imagepath}"      grid.row="0" width="350" height="165" horizontalalignment="center"      verticalalignment="stretch" automationproperties.name="{binding title}"      visibility="{binding typedescription, relativesource={relativesource      mode=templatedparent}, converter={staticresource texttovis}}"/> 

after hours of searching, found stackoverflow answer similar question. answer add propertychanged function propertymetadata. i'm not sure yet means or why needed here, works properly:

    public static readonly dependencyproperty sourceimageresourceidproperty =          dependencyproperty.register("sourceimageresourceid", typeof(string), typeof(waitingimagecontrol), new propertymetadata( string.empty, onsourcepathpropertychanged ));       private static void onsourcepathpropertychanged(dependencyobject d, dependencypropertychangedeventargs e)     {         (d waitingimagecontrol).sourceimageresourceid = e.newvalue.tostring();     } 

the onsourcepathpropertychanged function gets called , property gets set should.

now hope wasn't 1 of twenty other experiments actualy fixed this!


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 -