2 回答
TA贡献1951条经验 获得超3个赞
我想出了这个非常天真的解决方案:
XAML:
<BoxView x:Name="measureViewBox"
Grid.RowSpan="3" Grid.ColumnSpan="2"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Opacity="0"/>
<Label x:Name="myLabel"
Grid.RowSpan="3" Grid.ColumnSpan="2"
HorizontalTextAlignment="Center" VerticalTextAlignment="Center"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Text="ABCD">
后面的代码:
private void ContentView_SizeChanged(object sender, EventArgs e)
{
double fontSize = measureViewBox.Width;
myLabel.FontSize = fontSize;
SizeRequest measurement = myLabel.Measure(double.PositiveInfinity, double.PositiveInfinity);
while (measurement.Request.Width >= measureViewBox.Width)
{
fontSize -= 2;
myLabel.FontSize = fontSize;
measurement = myLabel.Measure(double.PositiveInfinity, double.PositiveInfinity);
}
}
当我在 UWP 中调整窗口大小时,它非常滞后,但至少现在,它完成了工作。我将在未来尝试改进这一点,因此任何建议将不胜感激。
- 2 回答
- 0 关注
- 160 浏览
添加回答
举报