Concatenate strings instead of using a stack of TextBlocks

后端 未结 4 1074
北荒
北荒 2020-12-04 09:43

I want to show a list of Customer objects in a WPF ItemsControl. I\'ve created a DataTemplate for this:

    

        
4条回答
  •  一向
    一向 (楼主)
    2020-12-04 10:16

    There is StringFormat property (in .NET 3.5 SP1), which you probably can use. And usefull WPF binding cheat sheat can found here. If it doesn't help, you can allways write your own ValueConverter or custom property for your object.

    Just checked, you can use StringFormat with multibinding. In your case code will be something like this:

    
      
        
            
            
        
      
    
    

    I had to start format string with space, otherwise Visual Studio wouldn't build, but I think you will find way get around it :)

    Edit
    The space is needed in the StringFormat to keep the parser from treating {0} as an actual binding. Other alternatives:

    
    
    
    
    
    
    
    
    

提交回复
热议问题