c# - How to programatically set the binding of a textbox with stringformat? -


how programmatically following (from xaml):

<textbox name="orderdatetext"          text="{binding path=orderdate, stringformat=dd-mm-yyyy}"  public datetime orderdate 

right have following

textbox txtboxorderddate = new textbox(); 

and know need like

  binding bindingorderdate = new binding();   bindingorderdate.source = "orderdate"; 

but stuck here ... not sure how proceed apply stringformat nor sure source correct way (should using elementname?)

let mainwindow class name. change mainwindow in below code class name.

public datetime orderdate {     { return (datetime) getvalue(orderdateproperty); }     set { setvalue(orderdateproperty, value); } }  public static readonly dependencyproperty orderdateproperty =     dependencyproperty.register("orderdate",                                 typeof (datetime),                                   typeof (mainwindow),                                 new propertymetadata(datetime.now, // default value property                                                      new propertychangedcallback(onorderdatechanged)));  private static void onorderdatechanged(object sender, dependencypropertychangedeventargs args) {     mainwindow source = (mainwindow) sender;      // add handling code     datetime newvalue = (datetime) args.newvalue; }  public mainwindow() {     initializecomponent();      orderdatetext.datacontext = this;     var binding = new binding("orderdate")         {             stringformat = "dd-mm-yyyy"         };     orderdatetext.setbinding(textbox.textproperty, binding);      //testing     orderdate = datetime.now.adddays(2);   } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -