admin管理员组文章数量:1297094
I have a scenario where I have several Entry controls that often have text that overflows what the entry control can show. I am trying to keep the text left aligned so I am using HorizontalTextAlighnment="Start" and it will display properly when IsReadOnly="False" but if I set the Entry to IsReadOnly="True" the text in the entry field will right align.
Here is a simple xaml page demonstrating the issue:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=";
xmlns:x=";
x:Class="MauiBugExample.MainPage">
<ScrollView>
<VerticalStackLayout x:Name="PageVerticalStackLayout"
Padding="30,0"
Spacing="25">
<Label Text="HorizontalTextAlignment=Start IsReadonly=False" />
<Entry
HorizontalTextAlignment="Start"
HorizontalOptions="FillAndExpand"
Text="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
IsReadOnly="False"/>
<Label Text="HorizontalTextAlignment=Start IsReadonly=True" />
<Entry
HorizontalTextAlignment="Start"
HorizontalOptions="FillAndExpand"
Text="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
IsReadOnly="True"/>
</VerticalStackLayout>
</ScrollView>
This is what the output looks like. The first line where it is not read only is correctly left aligned where the second line that is readonly is right aligned when it should be left aligned:
Issue only presents if the text overflows the size of the control. If I have less text in the entry field it will stay left aligned even if ReadOnly=True
I have a scenario where I have several Entry controls that often have text that overflows what the entry control can show. I am trying to keep the text left aligned so I am using HorizontalTextAlighnment="Start" and it will display properly when IsReadOnly="False" but if I set the Entry to IsReadOnly="True" the text in the entry field will right align.
Here is a simple xaml page demonstrating the issue:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft/winfx/2009/xaml"
x:Class="MauiBugExample.MainPage">
<ScrollView>
<VerticalStackLayout x:Name="PageVerticalStackLayout"
Padding="30,0"
Spacing="25">
<Label Text="HorizontalTextAlignment=Start IsReadonly=False" />
<Entry
HorizontalTextAlignment="Start"
HorizontalOptions="FillAndExpand"
Text="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
IsReadOnly="False"/>
<Label Text="HorizontalTextAlignment=Start IsReadonly=True" />
<Entry
HorizontalTextAlignment="Start"
HorizontalOptions="FillAndExpand"
Text="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
IsReadOnly="True"/>
</VerticalStackLayout>
</ScrollView>
This is what the output looks like. The first line where it is not read only is correctly left aligned where the second line that is readonly is right aligned when it should be left aligned:
Issue only presents if the text overflows the size of the control. If I have less text in the entry field it will stay left aligned even if ReadOnly=True
Share Improve this question asked Feb 11 at 17:50 LarryDevLarryDev 1301 silver badge6 bronze badges 2 |1 Answer
Reset to default 1You can add a custom mapping to EntryHandler
to set the cursor position to the start whenever the Entry
is read-only.
EntryHandler.Mapper.AppendToMapping("CustomPosition", (h, v) =>
{
#if ANDROID
if (v.IsReadOnly)
{
h.PlatformView.SetSelection(0);
}
#endif
});
Add this during app startup, for example, in MauiProgram.cs
.
本文标签:
版权声明:本文标题:Maui Entry HorizontalTextAlignment=Start not left aligning text when text larger then entry field and IsReadOnly=true on Android 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741643197a2390036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
CursorPosition="0"
help? – Stephen Quan Commented Feb 11 at 23:53