.MAUI 标签未通过 InvokeOnMainThreadAsync 更新

问题描述 投票:0回答:1

我是 .MAUI 新手,使用 VS2022 中的默认 MAUI 项目(单击按钮) 我不是仅仅单击按钮并更新其.Text,而是通过事件获取数据。 但 UI 中的 .Text 从未更新。即使在调试时,即使在分配 .TEXT 之后,调试器也始终在 CounterBtn.Text 处显示“旧”值。 怎么了?

       private void OnMessageReceived(object? sender, PioneerEventArgs e)
        {
            Console.WriteLine("OnMessageReceived {0} {1}", e.FunctionName, e.PropertyValue);
            CounterBtn.Text = $"Pio {e.FunctionName} {e.PropertyValue}";


            MainThread.InvokeOnMainThreadAsync(() =>
            {
                // Code to run on the main thread
                CounterBtn.Text = $"Pio {e.FunctionName} {e.PropertyValue}";
            });
        }

期待:更新 GUI

android .net maui
1个回答
0
投票

是的,它位于 MainPage.xaml 的代码后面,所以在 MainPage.xaml.cs 中

© www.soinside.com 2019 - 2024. All rights reserved.