Find List of binded property in a Depedency Property in WPF C# -


i'm having wpf custom control

<local:supercontrol>     <local:supercontrol.sbitem>         <multibinding stringformat="{}name: {0} ({1})">             <binding path="name" />             <binding path="id" />         </multibinding>     </local:supercontrol.sbitem> </local:supercontrol> 

the viewmodel property

public string name { get; set; } public string id { get; set; } 

consider value property

name = "john"; id = "stk001"; 

the custom control

public class supercontrol : itemscontrol {     public static readonly dependencyproperty sbitemproperty = dependencyproperty.register("sbitem", typeof(string), typeof(bautocomplete), new propertymetadata(null));      public string sbitem     {         { return (string)getvalue(sbitemproperty); }         set { setvalue(sbitemproperty, value); }     }      public override void onapplytemplate()     {         string name = sbitem;         string id = sbitem;         string stringformat = sbitem;     } } 

consider piece of code in custom control

public override void onapplytemplate() {     string name = sbitem;     string id = sbitem;     string stringformat = sbitem; } 

here need value of binded property name, id , string format dependency property sbitem. kindly assist me.

you cannot binded values in applytemplate method. called before binding.

so, provide callback property change using new propertymetadata(null,new propertychangedcallback(onpropertychanged)) in dp definition.

private static void onpropertychanged(dependencyobject d, dependencypropertychangedeventargs e)         {             string value = (string)e.newvalue;             string name = value.split(new char[] { ':' })[1].split(new char[] { '(' })[0].trim();             string id = value.split(new char[] { ':' })[1].split(new char[] { '(' })[1].split(new char[] { ')' })[0].trim();             string formatting = bindingoperations.getmultibinding(d, mybutton.mypropertyproperty).stringformat;         } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -