WPF Binding and Dynamically Assigning StringFormat Property

前端 未结 5 1314
慢半拍i
慢半拍i 2021-01-04 12:06

I have a form that is generated based on several DataTemplate elements. One of the DataTemplate elements creates a TextBox out of a class that looks like this:



        
5条回答
  •  我在风中等你
    2021-01-04 12:20

    Just bind the textbox to the instance of a MyTextBoxClass instead of MyTextBoxClass.Value and use a valueconverter to create a string from the value and formatstring.

    Another solution is to use a multivalue converter which would bind to both Value and FormatString.

    The first solution don't support changes to properties, that is if value or formatstring changes the value converter will not be called like it would be if you are using a multivalueconverter and binding directly to the properties.

提交回复
热议问题