UWP和绑定到不同项目中的静态类 [英] UWP and Binding to static class in different project

查看:66
本文介绍了UWP和绑定到不同项目中的静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个公共项目中有一个静态类,在该项目中,我所有的属性以及所有文本(例如,我所有的标题)都有

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

我想知道如何将TextBlock Text绑定到该值.

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

我尝试使用Text = {x:Static ...},但未找到Static.

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

谢谢

推荐答案

{x:static ...}在UWP中不存在.

{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.

然后,将该类声明为资源,并将其用作绑定的源.我建议您声明资源在全球可用的位置,例如app.xaml.

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}" />

这篇关于UWP和绑定到不同项目中的静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆