Page 1 of 1

[Unity] StringFormat overwriting data from source

Posted: 19 May 2017, 14:37
by polycular

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.

Re: [Unity] StringFormat overwriting data from source

Posted: 22 May 2017, 20:28
by sfernandez
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?