单词不包装?
我目前已经将以下属性设置为一个按钮,并且我希望它可以包含文字包装。我希望文本动态地安装在按钮内,但仍未从按钮上运行,但它仍在按钮...有什么想法吗?
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="quiz_app.Views.StudyPage"
Title="Study">
<StackLayout BackgroundColor="White"
Padding="100"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<VerticalStackLayout>
<Button
Text="How much wood could a woodchuck chuck if a woodchuck could chuck wood?"
FontSize="40"
TextColor="Black"
FontFamily="Helvetica"
BackgroundColor="#CCFFCC"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
BorderWidth="5"
HeightRequest="400"
BorderColor="#82D682"
LineBreakMode='WordWrap'>
</Button>
</VerticalStackLayout>
</StackLayout>
</ContentPage>
I have currently set the following properties to a button, and I want it to word wrap. I want the text to fit inside the button dynamically and not run off the button but it's still running off the button... any ideas?
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="quiz_app.Views.StudyPage"
Title="Study">
<StackLayout BackgroundColor="White"
Padding="100"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<VerticalStackLayout>
<Button
Text="How much wood could a woodchuck chuck if a woodchuck could chuck wood?"
FontSize="40"
TextColor="Black"
FontFamily="Helvetica"
BackgroundColor="#CCFFCC"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
BorderWidth="5"
HeightRequest="400"
BorderColor="#82D682"
LineBreakMode='WordWrap'>
</Button>
</VerticalStackLayout>
</StackLayout>
</ContentPage>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢@ewerspej的选择,但由于某种原因,我无法让GesturerCognizer工作,因为它没有将其视为成员,所以我只是在边境内部包装了一个标签,这做了我想做的事情。
下面编辑的代码:
Thank you @ewerspej for the alternative but I could not get the GestureRecognizer to work for some reason it wasn't recognizing it as a member so I just wrapped a label inside of a border and that did what I wanted to do.
Edited code below:
如果您参考 https://github.com/dotnet/ MAUI/essugy/9102 您会看到按钮中的LineBreakMode已“固定”。但是有副作用,看来文本包装不完全居中:
实际:
期望:
我举起一个讨论论坛github.com/dotnet/maui/discussions/27592“ rel =“ nofollow noreferrer”> https://github.com/dotnet/maui/discussions/27592 讨论这一点。
我一直在寻找解决方法,我注意到这里的其他答案选择不使用
button
,而是border+Label
带有tapgesturererecognizer
。这种解决方法的缺点是丢失了可访问的键盘转换。为了保持两全其美,我已经捣碎了
网格+边框+标签+按钮
。正确的视觉表示由border+标签
提供。与无障碍键盘快捷键的正确用户交互由Invisible按钮
提供。网格
将两者捣碎,以便border+标签
和button
都是几何大小和位置。The status of this issue has changed, if you refer to https://github.com/dotnet/maui/issues/9102 you will see that LineBreakMode in Button has been "fixed". There is a side effect though, it appears that the text is wrapped not perfectly centered:
Actual:
Expected:
I raise a discussion forum https://github.com/dotnet/maui/discussions/27592 to discuss this.
I have been looking at workarounds and I noticed the other answers here have opted not to use
Button
but aBorder+Label
with aTapGestureRecognizer
. The downside of this workaround is the loss of accessible keyboard-shortcuts.To keep the best of both worlds, I have mashed up
Grid+Border+Label+Button
. The correct visual representation is provided byBorder+Label
. The correct user interaction with accessible keyboard shortcuts is supplied by an invisibleButton
. TheGrid
mashes up the two so that both theBorder+Label
and theButton
are the same geometric size and position.只是为了完整的清酒:
使用
tapgestureRecognizer
的可能解决方案可以如下:Just for completeness sake:
A possible solution using a
TapGestureRecognizer
could look as follows: