[Unity] StringFormat overwriting data from source
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.
Due to this forum post I was expecting this to work. Anyone having a hint, what might be wrong here.
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.
Code: Select all
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);
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: [Unity] StringFormat overwriting data from source
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:
Could you please create a ticket to track this bug?
Code: Select all
{Binding Value, StringFormat=The value is {0:G}}
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 9 guests