0

I can't set the FontSize of the Text in a TextBlock, since the TextBox is in a Viewbox. Why?

<Grid Margin="35,30,35,0" ShowGridLines="False" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition MinWidth="270 px" Width="2*"/>
        <ColumnDefinition Width="5*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition  />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Border Grid.Row="0" Grid.Column="0" BorderBrush="Black" BorderThickness="1,1,1,0" />
    <Viewbox>
        <TextBlock  Margin="10,5,0,5" Grid.Row="0" Grid.Column="0">Team:</TextBlock>
    </Viewbox>
    <Border Grid.Row="1" Grid.Column="0" BorderBrush="Black" BorderThickness="1,1,1,0" />
    <TextBlock Margin="10,5,0,5" Grid.Row="1" Grid.Column="0">Beschreibung:</TextBlock>
    <Border Grid.Row="2" Grid.Column="0" BorderBrush="Black" BorderThickness="1,1,1,0" />
    <TextBlock Margin="10,5,0,5" Grid.Row="2" Grid.Column="0">Milestone:</TextBlock>
    <Border Grid.Row="3" Grid.Column="0" BorderBrush="Black" BorderThickness="1,1,1,1" />
    <TextBlock Margin="10,5,0,5" Grid.Row="3" Grid.Column="0">Status:</TextBlock>
    <Border Grid.Row="0" Grid.Column="1" BorderBrush="Black" BorderThickness="0,1,1,0" />
    <TextBlock x:Name="tb_Team_dyn" Margin="10,5,0,5"  Grid.Row="0" Grid.Column="1"
               FontWeight="Bold" Text="{Binding Data.Team}" TextWrapping="Wrap"></TextBlock>
    <Border Grid.Row="1" Grid.Column="1" BorderBrush="Black" BorderThickness="0,1,1,0" />
    <TextBlock x:Name="tb_Descr_dyn" Margin="10,5,0,5" Grid.Row="1" Grid.Column="1"
               FontWeight="Bold" Text="{Binding Data.Description}" TextWrapping="Wrap"/>
    <Border Grid.Row="2" Grid.Column="1" BorderBrush="Black" BorderThickness="0,1,1,0" />
    <TextBlock x:Name="tb_Milestone_dyn" Margin="10,5,0,5" Grid.Row="2" Grid.Column="1"
               FontWeight="Bold" Text="{Binding Data.Milestone}" TextWrapping="Wrap"/>
    <Border Grid.Row="3" Grid.Column="1" BorderBrush="Black" BorderThickness="0,1,1,1" />
    <StackPanel Margin="10,5,0,5" Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
        <Image  x:Name="imgSmile" MaxWidth="38" Source="{Binding Data.Smiley}" />
        <TextBlock x:Name="tb_Status_dyn" Margin="{Binding Data.SmileyMargin}"
                   Foreground="{Binding Data.Col}" FontWeight="Bold"
                   Text="{Binding Data.Status}" TextWrapping="Wrap"></TextBlock>
    </StackPanel>
</Grid>

I can set the FontSizes of all of the TextBlocks but not of the TextBlock which is in the Viewbox.

4

2 回答 2

2

请记住,FontSize 设置文本的实际大小,但 Viewbox 会在文本布局和呈现后对其进行缩放。如果将具有固定宽度和高度的元素放置在 Viewbox 中,您将看到相同的效果。Viewbox 本身不会更改 Width、Height 或 FontSize 属性,但最终呈现效果会有所不同。

您实际上正在寻找的是 Viewbox 本身的初始布局,它将使其初始大小等于 TextBlock 的初始大小,这将有效地将 Viewbox 的缩放设置为 1:1。您可以根据您的应用程序以多种方式实现此目的(直接在代码中,与 ValueConverters 的绑定等),但基本方法是测量父元素的初始大小并设置适当的边距以缩小视图框内的分配给它的布局区域。这将允许 Viewbox 与父级一起更改大小,因为它保持您设置的边距。还要查看 Viewbox 上的 StretchDirection、MinHeight 和 MinWidth。

于 2010-01-20T22:10:29.013 回答
1

一些示例代码会有所帮助。在我的脑海中......文本框是否设置为多行?如果不是,内部文本可能会与文本框一起拉伸。

于 2010-01-15T15:31:36.880 回答