简体   繁体   English

MAUI android渲染页面

[英]MAUI android rendering page

I am starting using the visual studio 2022 v. 17.3 preview 2 In the startup program that shows the dotnet_bot image and a button with text " Click Me"我开始使用 Visual Studio 2022 v. 17.3 预览 2 在显示 dotnet_bot 图像和带有文本“单击我”的按钮的启动程序中

now when you click the button text will change to "Clicked 15 times" ( number change accoring to count value according the following code:现在,当您单击按钮时,文本将更改为“单击 15 次”(根据以下代码的计数值更改数字:

private void OnCounterClicked(object sender, EventArgs e)
{
        count++;

        if (count == 1)
            CounterBtn.Text = $"Clicked {count} time";
        else
            CounterBtn.Text = $"Clicked {count} times";
        
        SemanticScreenReader.Announce(CounterBtn.Text);
    }

so the text will change but the button size will not adjust .. and the text will be clipped as the following image:所以文本会改变但按钮大小不会调整..文本将被剪裁为下图:

在此处输入图像描述

I tried to search online and on github and microsoft documentation.. I couldn't find out how to force the button to adjust its size to the text property我尝试在线搜索以及在 github 和 microsoft 文档上搜索.. 我找不到如何强制按钮将其大小调整为 text 属性

This happen only in Android but not in windows这仅在 Android 中发生,但在 Windows 中不会发生

I tested android phone emulator (Pixel 5 API 30 (Android 11.0 ) Same behavior on android tablet (Tablet M-DPI 10.1in - API 31 ( android 12)我测试了 android 手机模拟器 (Pixel 5 API 30 (Android 11.0)) 在 android 平板电脑上的行为相同 (Tablet M-DPI 10.1in - API 31 (android 12)

The solution I found which is not accepted is我发现的不被接受的解决方案是

to use any entry element that will make the keyboard pop out.. then and only then the page will re-render and the button will expand to show the full text "clicked 15 times"使用任何会使键盘弹出的条目元素..然后只有这样页面才会重新呈现,并且按钮将展开以显示全文“点击 15 次”

So my question is :所以我的问题是:

What am I missing here?我在这里想念什么? How to force the page to rerender?如何强制页面重新呈现? Or is it a bug in MAUI ??还是 MAUI 中的错误?

Update更新

Yes,it is a known issue in android.是的,这是 android 中的一个已知问题。

You can follow it up here:你可以在这里跟进:

https://github.com/dotnet/maui/pull/8136 https://github.com/dotnet/maui/pull/8136

https://github.com/dotnet/maui/issues/8028 https://github.com/dotnet/maui/issues/8028

But as a workaround,you can try to change the property of Button CounterBtn from但作为一种解决方法,您可以尝试将 Button CounterBtn的属性从

HorizontalOptions="Center"

To

HorizontalOptions="Fill" 

or或者

HorizontalOptions="FillAndExpand"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM