User avatar
polycular
Topic Author
Posts: 19
Joined: 29 Sep 2015, 18:18

[Unity] StringFormat overwriting data from source

19 May 2017, 14:37

Hey,

I have encountered a problem, which i could not solve. It might be due to a misconception, but here this is what we have experienced. We have a data source "campaign" with a Name attribute, which is already filled in (from parsing a local JSON file). In a TextBlock in XAML we want to have the Name displayed with some other text using StringFormat, but this seems to overwrite our data, cause without the StringFormat the data binding works as expected.

Binding b = new Binding()
{
	Source = Datahub.Instance.Campaign,
	Path = new PropertyPath("Name"),
	Mode = BindingMode.OneWay,
	UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
	StringFormat = "Welcome to tour {0}. Good luck!"
};
	
View.TbTeamTitle.SetBinding(TextBlock.TextProperty, b);
Due to this forum post I was expecting this to work. Anyone having a hint, what might be wrong here.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: [Unity] StringFormat overwriting data from source

22 May 2017, 20:28

It seems that StringFormat is not working if source property is of type string. It's only working when binding to number properties and using a type specifier like:
{Binding Value, StringFormat=The value is {0:G}}
Could you please create a ticket to track this bug?

Who is online

Users browsing this forum: Google [Bot] and 0 guests