使用本机Xamarin.android项目中的Xamarin.Forms控件?
让我在这里解释当前情况。 我有一个主要的Xamarin.Forms项目,该项目由本机项目也正在使用的主要UI ContentPage组成,因为这就是Xamarin.Forms项目的工作方式。
事实是,我想使用MainActivity.cs内部Xamarin.android Project中的Mainpage.XAMARIN.FORMS项目的mainpage.xaml中使用的控件(例如标签)。在mainActivity.cs中,我想更新控件的值,以便将其显示在UI上。.
我将标签命名为'lbltest',但是mainActivity.cs无法找到此控件。当然,这是有意义的,因为此控制不存在于Xamarin.android项目中。
您是否知道如何在本机Xamarin.android项目中访问此Xamarin.Forms控件?我会感谢这一点,并提前感谢。
Let me explain the current situation here.
I have a main Xamarin.Forms project that consists of a main UI contentpage that is also being used by the Native Projects, because this is how a Xamarin.Forms project works.
The thing is that I want to use a control (such as a Label) that is being used in the MainPage.xaml of the main Xamarin.Forms project within the native Xamarin.Android project, inside MainActivity.cs. Within MainActivity.cs I want to update the value of the control, so that this is being displayed on the UI..
I have named the label as 'lblTest', however MainActivity.cs is unable to find this control. This makes sense of course, because this control does not exist within the Xamarin.Android project.
Do you have any idea how I can access this Xamarin.Forms control within a native Xamarin.Android project? I would appreciate this and thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如杰森(Jason)提到的那样,
MendagingCenter
是一个工作但凌乱的解决方案。另一种方法是先获取页面访问,然后在页面内定义的公共方法中更新标签。
例如,如果页面是应用程序的主页,则可以首先定义公共方法。
并更新Android项目中的标签。
As Jason mentioned ,
MessagingCenter
is a working but messy solution.Another way is to get access the page first and then update the Label in a public method which is defined inside the page .
For example , if the page is MainPage of App, you can define a public method first .
And update the label in Android project.