Can we concat two properties in data binding?

后端 未结 6 523
别跟我提以往
别跟我提以往 2021-02-01 13:04

Can we concat two properties together in binding expression? If possible without converter or without writing two textblocks and setting them individually?

6条回答
  •  暖寄归人
    2021-02-01 14:05

    You can add a new property with a getter that performs the concatenation.

    Say you have FirstName and LastName properties. You can then define a Name property as follows:

    public string Name { get { return FirstName + " " + LastName; } }
    

    This will work well, but you should be aware that you cannot do two-way binding for a read-only property. Also you may want to implement property changed notification for the concatenated property in the setters for the source properties.

提交回复
热议问题