我正在Silverlight中爲嵌入式窗口工作,並且希望將文本放到TextBlock上,如圖片所示,我希望textBlock適合文本(我想刪除附加圖片中的黃色空間)如何使TextBlock大小適合文本大小
有人可以幫助我?
最好的問候, 盧卡
這是我目前使用的XAML:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="FullTest.PUIsocUI"
d:DesignWidth="480" d:DesignHeight="272">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Height="64" Grid.Row="1">
<RadioButton x:Name="PowerMeasurement" GroupName="PowerTabControls" IsChecked="True" Checked="PowerMeasurement_Checked" Unchecked="PowerMeasurement_Unchecked" Content="POWER" BorderThickness="0"/>
<RadioButton x:Name="PowerMode" GroupName="PowerTabControls" Checked="PowerMode_Checked" Unchecked="PowerMode_Unchecked"/>
<RadioButton x:Name="PowerLimit" GroupName="PowerTabControls" IsChecked="False" Click="PowerLimit_Click" Checked="PowerLimit_Checked" Unchecked="PowerLimit_Unchecked"/>
</StackPanel>
<Grid>
<Grid x:Name="PowerMeasurementPage" Margin="0,0,0,64" >
<!-- tab page za meritev-->
<TextBlock Text="POWER" Style="{StaticResource FunctionNameTextBlockStyle}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBlock Text="11.555" Style="{StaticResource ResultNameTextBlockStyle}" />
</Grid>
<Grid x:Name="PowerModePage" Margin="0,0,0,64">
<!-- tab page za Mode-->
</Grid>
<Grid x:Name="PowerLimitPage" Margin="0,0,0,64">
<!-- tab page za Limita-->
</Grid>
</Grid>
</Grid>
<Style TargetType="TextBlock" x:Key="FunctionNameTextBlockStyle">
<Setter Property="FontFamily" Value="ALTERNATE_GOTHIC#AlternateGothic2 BT"/>
<Setter Property="FontSize" Value="44"/>
<Setter Property="Margin" Value="57,27,0,0"/>
</Style>
這是我想 - >
您的目標只是爲了使文本項目的對齊更容易?如果是這樣,只需使用負頂部邊距。問題在於文本塊使用字體本身定義的填充來確定TextBlock的大小。 – 2012-08-03 10:29:57
是的,這正是我想要的,使對齊更容易:) – 2012-08-03 13:33:46
我可以得到你想要的效果,在TextBlock本身使用邊距,但在樣式設置器的負邊緣似乎沒有效果。 – 2012-08-03 15:16:46