Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调整标签字体大小_C#_Wpf_Label - Fatal编程技术网

C# 调整标签字体大小

C# 调整标签字体大小,c#,wpf,label,C#,Wpf,Label,我想动态调整标签内容;文本较大时,调整标签字体大小以适应标签空间 <Label Name="lblResult" Content="0" Margin="0,-1,-222,0" VerticalAlignment="Top" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" FontFamily="Helvetica Neue" Foreground="White" Bac

我想动态调整标签内容;文本较大时,调整标签字体大小以适应标签空间

<Label Name="lblResult" Content="0" Margin="0,-1,-222,0" VerticalAlignment="Top"
       HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom"
       FontFamily="Helvetica Neue" Foreground="White" Background="Black"
       Height="87" FontSize="63" RenderTransformOrigin="0.5,0.5" Padding="9"
       ContentStringFormat="{}{0:#,0}" FontWeight="Light" ClipToBounds="True" />


谢谢

WPF Viewbox控件将其内容增加/缩小到可用空间:

只需将标签放置在ViewBox中:

<Viewbox Stretch="Uniform">
    <Label Name="lblResult" Content="Moez Rebai" VerticalAlignment="Top"
   HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom"
   FontFamily="Helvetica Neue" Foreground="White" Background="Black"
   Height="87" FontSize="63" RenderTransformOrigin="0.5,0.5" Padding="9"
   ContentStringFormat="{}{0:#,0}" FontWeight="Light" ClipToBounds="True" />
</Viewbox>


当然,您的Viewbox通常是通过其容器进行缩放的,但希望您能理解这一点

当我把标签代码放在视图框中时,标签消失了,即使我运行代码,也没有任何标签。我编辑了前面的代码,我尝试了它,效果很好。你能试试看,告诉我你得到了什么吗