Binding string property to object

后端 未结 1 361
渐次进展
渐次进展 2021-01-24 23:56

Say I have a class like this:

public class MyClass
{
    public string Name;
    public int Id;

    public override string ToString()
    {
        return this.         


        
相关标签:
1条回答
  • 2021-01-25 00:54

    There are certain conversions for which WPF will apply an implicit converter on a binding if the bound types don't match. Converting to a string can be done by calling ToString() the same way it's implicitly called in other areas of the .Net framework.

    The Text binding of the TextBox is two-way by default and therefore can't use an implicit converter as a string can't be converted back to your MyClass type. The binding for the display template in the grid column is one way and can therefore use an implicit converter. I would imagine that you would get a binding error if you put the grid column into edit mode by clicking on it.

    0 讨论(0)
提交回复
热议问题