Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Label Text using a static resource in the code behind #5

Open
npagare opened this issue Dec 10, 2018 · 1 comment
Open

Setting Label Text using a static resource in the code behind #5

npagare opened this issue Dec 10, 2018 · 1 comment

Comments

@npagare
Copy link

npagare commented Dec 10, 2018

Hi Johan, thank you sharing this repo.

I am trying to set provide a static resource in the OnPropertyChanged event for setting the static resource to the Label.Text by concatenating the value of a bindable property using a stringbuilder

e.g. from your repo , inside the property changed event

            BaseIcon.Style = (Style)Application.Current.Resources["FontAwesomeWeb550Regular"];

            StringBuilder baseIconSb = new StringBuilder();
            baseIconSb.Append("\"");
            baseIconSb.Append("{x:Static helpers:FontAwesomeWeb550Font.");
            baseIconSb.Append(BaseIconSrc);
            baseIconSb.Append("}");
            baseIconSb.Append("\"");

            BaseIcon.Text = baseIconSb.ToString();

But, when rendered, it shows the text value in the label starting "{x ….. depending on the side of the label width set.

image

Any thought, what I may be missing ?

Thanks

@Polarts
Copy link

Polarts commented Dec 12, 2018

When you set the text via code-behind, it takes the string literally as is to display rather than run it on the XAML compilation engine. Thus, your string is presented plainly as "{x:Static helpers:FontAwesomeWeb550Font.[BaseIconSrc]}" rather than fetching the resource from the dictionary and presenting it.

What you should do in this case is:
BaseIcon.Text = (string)Application.Current.Resources["FontAwesomeWeb550Font"+BaseIconSrc];

Something along these lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants