wifi message received event update text in xamarin forms

2022-03-13T11:20:36.15+00:00

I have an event which come from wifi message in xamarin and i want it operate a function to update the text in lable or entry to dispalay the text the problem that i recive text and can not display it

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points Microsoft Vendor
    2022-03-14T03:05:32.147+00:00

    Hello,​

    i want it operate a function to update the text in lable or entry to dispalay the text the problem that i recive text

    You can use Xamarin.Forms MessagingCenter to achieve it. For example, you receive the message from the background service or other native platform(such as Android BroadCastReceiver). You can send Message by

       MessagingCenter.Send<App, string>(App.Current as App, "OneMessage", "this is recieved wifi information");  
    

    If you have a Label in the MainPage.xaml called myLabel, when you receive the Message, you can update it like following background code.

       public MainPage()  
               {  
                   InitializeComponent();  
                   MessagingCenter.Subscribe<App, string>(App.Current, "OneMessage", (snd, arg) =>  
                   {  
                       Device.BeginInvokeOnMainThread(() => {  
                             
                           //Update the Label‘s text, if received the Message  
                           myLabel.Text = arg;  
                       });  
                   });  
               }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.