Tuesday 15 September 2015

c# - WPF - Binding in XAML to an object created in the code behind -


Can an object created in code (i.e. C #) be used to force XAML?

For example:

  Public class MyForm {Private MyComplexObject complexObject; Public MyForm () {InitializeComponent (); } Public OnButtonClick (Object Sender, RoutedEventArgs E) {complexObject = new MyComplexObject (); }}  

Complex object is not created until the button is clicked. But once I click on that button, I have a text box which is starting to show the complexObject.ID id.

I want to do it in XML if it is possible.

Can this be done? if so, how?

There is a possibility that your XML should be tied to an asset behind your code. Recipient complex object for that property ID will return, if complex object! = Null otherwise, it gives something "default", whether it is zero or 0 or default ( type of ID ). Similarly, for a complex asset the setter must assign value to complex object if there is a complex object, again, not blank.

  public entry id {get (if (complexObject! = Null) back complex object.ID; return 0; // or empty or some appropriate default} set {if (complexObject! = Null) ComplexObject.ID = value;}}  

No comments:

Post a Comment