views:

304

answers:

2

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

                <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"></TextBlock>
                <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"></TextBlock>
                <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.

+1  A: 

Some sample code would be helpful. Off the top of my head... is the textbox set to multiline? If not the inner text will probably stretch along with the textbox.

sdcoder
+2  A: 

Keep in mind that the FontSize sets the actual size of the text but the Viewbox then scales it after the text is laid out and rendered. You will see the same effect if you place an element with a fixed Width and Height in a Viewbox. The Viewbox doesn't change the Width, Height, or FontSize properties themselves but the final rendering appears different.

What you're actually looking for is an initial layout for the Viewbox itself that will make its initial size equal to that of the TextBlock, which will effectively set the scaling of the Viewbox to 1:1. You can achieve this in a number of ways depending on your application (directly in code, Bindings with ValueConverters, etc) but the basic method would be to measure the initial size of a parent element and set appropriate Margins to scale down the Viewbox within the layout area assigned to it. This would then allow the Viewbox to change size along with its parent as it maintains the Margins that you set. Also look at the StretchDirection, MinHeight, and MinWidth on the Viewbox.

John Bowen