[Unity] StringFormat overwriting data from source
Posted: 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.
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);