What I mean is that DataContext property is of type object. If you set a string to it, it will always be just a string until you convert it into the object of the type you intend the data context to be.
Converting to and from string is no problem for known types because the implicit or explicit convertion is defined somewhere in the framework. If you have your own custom type you'll to provide these convertions.
Let's say you have your class like so:
The result of an object of type YourClass would be the string "YourNamespace.YourClass". If you want it to be, for instance the string in YourClassStringProperty value you'd have to either implicitly convert YourClass to string or override ToString method.
When your cenario is a XAML Binding, it is a whole diferent story and you'll have to provide XAML the tool to convert the string into YourClass object. Meaning providing explicitly a converter.
Bigsby, Lisboa, Portugal
Converting to and from string is no problem for known types because the implicit or explicit convertion is defined somewhere in the framework. If you have your own custom type you'll to provide these convertions.
Let's say you have your class like so:
namespace YourNamespace |
{ |
public class YourClass |
{ |
public string YourClassStringProperty |
{ get; set; } |
} |
} |
The result of an object of type YourClass would be the string "YourNamespace.YourClass". If you want it to be, for instance the string in YourClassStringProperty value you'd have to either implicitly convert YourClass to string or override ToString method.
When your cenario is a XAML Binding, it is a whole diferent story and you'll have to provide XAML the tool to convert the string into YourClass object. Meaning providing explicitly a converter.
Bigsby, Lisboa, Portugal