How to grow/shrink a TextBlock (Font Size) to the available space in WPF?

The WPF Viewbox control will grow / shrink its contents to the available space: http://www.wpftutorial.net/ViewBox.html Just place your TextBlock within a ViewBox: <Viewbox Stretch=”Uniform” Width=”50″ Height=”50″> <TextBlock Text=”Test” /> </Viewbox> Of course, your Viewbox is typically scaled by its container, but hopefully you get the idea!

Maximum number of lines for a Wrap TextBlock

Update (for UWP) In UWP Apps you don’t need this and can use the TextBlock property MaxLines (see MSDN) Original Answer: If you have a specific LineHeight you can calculate the maximum height for the TextBlock. Example: TextBlock with maximum 3 lines <TextBlock Width=”300″ TextWrapping=”Wrap” TextTrimming=”WordEllipsis” FontSize=”24″ LineStackingStrategy=”BlockLineHeight” LineHeight=”28″ MaxHeight=”84″>YOUR TEXT</TextBlock> This is all that … Read more

Data binding the TextBlock.Inlines

You could add a Dependency Property to a TextBlock Subclass public class BindableTextBlock : TextBlock { public ObservableCollection<Inline> InlineList { get { return (ObservableCollection<Inline>)GetValue(InlineListProperty); } set { SetValue(InlineListProperty, value); } } public static readonly DependencyProperty InlineListProperty = DependencyProperty.Register(“InlineList”,typeof(ObservableCollection<Inline>), typeof(BindableTextBlock), new UIPropertyMetadata(null, OnPropertyChanged)); private static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { BindableTextBlock textBlock = sender as … Read more

TextBlock with multiple spacing

if you write all your Runs in the same line, the empty space will go away. Basically a new line here is one empty space on the UI. <TextBlock Foreground=”DarkGray” VerticalAlignment=”Bottom” Margin=”0,0,0,8″><Run Text=”total length “/><Run Text=”{Binding TotalHours}” FontSize=”48″/><Run Text=”h “/><Run Text=”:” FontSize=”48″/><Run Text=”{Binding TotalMinutes}” FontSize=”48″/><Run Text=”m “/></TextBlock>

Add hyperlink to textblock WPF

Displaying is rather simple, the navigation is another question. XAML goes like this: <TextBlock Name=”TextBlockWithHyperlink”> Some text <Hyperlink NavigateUri=”http://somesite.example” RequestNavigate=”Hyperlink_RequestNavigate”> some site </Hyperlink> some more text </TextBlock> And the event handler that launches default browser to navigate to your hyperlink would be: private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { System.Diagnostics.Process.Start(e.Uri.ToString()); } To do it with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)