views:

1037

answers:

1

I'm trying to figure out how to change the font size of a textblock and textbox in Silverlight 2.0. in code behind. So far i've had no luck getting it done or find a referrence on how to do it.

thanks shannon

+2  A: 

You need to set the FontSize (also for TextBox) dependency property. This takes a double, as stated in MSDN:

A non-negative value that specifies the font size, measured in pixels. The default is 11.

To set this in code-behind, you can do something like this:

// Assuming you have a TextBlock called 'block'.
block.FontSize = 18;

// ...alternatively...
TextBlock.SetValue(TextBlock.FontSizeProperty, 18);
Jeff Yates
Thanks for the replie. I may have an issue before i even get to that point. I have lblAdjustFont.FontSize = 12 and recieve the message object refernece not set to an instance of an object. This message is coming up when i run the app in debugger mode. is there something i need to wrap that code with. Is the textblock not created at by this point in the compile process. The fontsize is being set in a event for a sliderbar.
jvcoach23
it might be helpful if you had the xaml as well.<TextBlock Height="18" HorizontalAlignment="Left" Margin="379,18,0,0" VerticalAlignment="Top" Width="123.608" TextWrapping="Wrap" d:LayoutOverrides="Height" x:Name="lblAdjustFont" FontFamily="Times New Roman" FontSize="12" ><Run Text="Adjust Size of Text"/><LineBreak/><Run Text=""/></TextBlock><Slider Height="24" HorizontalAlignment="Right" Margin="0,18,390,0" VerticalAlignment="Top" Width="110" x:Name="slFontSize" ValueChanged="slFontSize_ValueChanged" Maximum="24" Minimum="12" Value="16" SmallChange="1"/>
jvcoach23
Where are you setting the FontSize?
Jeff Yates