Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP and Binding to static class in different project

Tags:

I have a static class in a common project where I have all my property with all my text (for example, all my titles)

I want to know how I can bind my TextBlock Text to this value.

I tried Text={x:Static...} but Static is not found.

Thanks

like image 777
Naografix Avatar asked Oct 11 '16 13:10

Naografix


1 Answers

{x:static...} is not present in UWP.

You can still do something similar, but the class itself must not be static. The properties in the class can be static but you need to create an instance of that class. So you will need to ask for a change in the core lib.

Then you declare that class as a resource and use that as the source of your Bindings. I recommend you declare the resource where it's globally available, like app.xaml.

<Application.Resources>
    <lib:Class1 x:Key="c1"/>
</Application.Resources>
...
<TextBlock Text="{Binding Source={StaticResource c1}, Path=Text1}" />
like image 76
AlexDrenea Avatar answered Sep 26 '22 16:09

AlexDrenea