从其他页面访问对象 [英] Access objects from other pages
问题描述
我在MyPage.xaml中的TextBox1和MainPage.xaml中的TextBlock1都在xaml中。如何以编程方式设置TextBlock1.Text = TextBox1.Text?
I have TextBox1 in MyPage.xaml and TextBlock1 in MainPage.xaml all in xaml. How to set programatically TextBlock1.Text = TextBox1.Text?
推荐答案
我认为你不想这样做。 为了完成同样的事情,为什么不让每个页面都有自己的Viewmodel,其属性为文本,并在App中创建一个全局的属性? 然后,只需使用App全局属性获取每个View模型并设置其值
。 这样,观点不必试图了解彼此以及它们是否存在。
I don't think you want to do that. To accomplish the same thing, why not make each page have its own Viewmodel with a property bounnd to the Text and create a property in the App that is global? Then just make each of the Viewmodels get and set their values by using the App global property. That way the views don't have to try to know about each other and whether they even exist.
这篇关于从其他页面访问对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!