gpt4 book ai didi

xamarin.forms - Xamarin 在使用下划线时形成 BoxView 宽度太长

转载 作者:行者123 更新时间:2023-12-03 08:18:55 24 4
gpt4 key购买 nike

我正在使用 BoxView 在我的应用中添加下划线。我有几个非常短的标签 - 诸如"is"或“否”之类的文本。这是带有下划线的 BoxView 的其中一个标签的 XAML:

<StackLayout Orientation="Vertical" Grid.Row="5" Grid.Column="1" Margin="0,4,0,4" HorizontalOptions="Start" BackgroundColor="Purple" MinimumWidthRequest="1">
<Label x:Name="txtUseMetric" TextColor="Blue" FontSize="Small" Text="{Binding UseMetricText}" BackgroundColor="Yellow">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="Value_Tapped" CommandParameter="usemetric" />
</Label.GestureRecognizers>
</Label>
<BoxView BackgroundColor="Green" HeightRequest="1" MinimumWidthRequest="1" />
</StackLayout>

我的问题是 BoxView 的宽度总是超出我的文本我已经尝试覆盖我的 App.Xaml 文件中的 MinWidthRequest,如下所示:

<Style TargetType="BoxView">
<Setter Property="MinimumWidthRequest" Value="3" />
</Style>

但这并没有效果。我已经包含了屏幕截图供您查看。

仅供引用 - 黄色是标签的宽度。您看不到任何紫色(StackLayout 的背景色),因为 StackLayout 和 Label 的宽度相同。第二个屏幕截图显示了如果我删除 BoxView 时屏幕的样子 - 即 Label 和 StackLayout 的大小正确。

关于如何解决这个问题有什么建议吗?

BoxView 太长的屏幕截图使标签和 StackLayout 太长 Screen shot with BoxView Too Long

已删除 BoxView 并正确调整标签和堆栈布局大小的屏幕截图 enter image description here

最佳答案

请注意默认HorizontalOptionsLabel派生自 View :

默认值为 LayoutOptions。Fill 除非另有说明。

在“Use Metric”标签上添加Horizo​​ntalOptions="Start":

<Label x:Name="txtUseMetric" TextColor="Blue" FontSize="Small" 
Text="{Binding UseMetricText}" BackgroundColor="Yellow"
HorizontalOptions="Start">
<BoxView BackgroundColor="Green" HeightRequest="1"
WidthRequest="{Binding Path=Width, Source={x:Reference txtUseMetric}"
HorizontalOptions="Start"/>

关于xamarin.forms - Xamarin 在使用下划线时形成 BoxView 宽度太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47636459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com