Why isn’t TextBox.Text in WPF animatable?

Trying to animate the TextBox manually …. var timeline = new StringAnimationUsingKeyFrames(); timeline.KeyFrames.Add(new DiscreteStringKeyFrame(“Goodbye”, KeyTime.FromTimeSpan(new TimeSpan(0,0,1)))); textControl.BeginAnimation(TextBox.TextProperty, timeline); …reveals a more useful error message. The last line fails with the following ArgumentException: ‘Text’ property is not animatable on ‘System.Windows.Controls.TextBox’ class because the IsAnimationProhibited flag has been set on the UIPropertyMetadata used to associate the property … Read more

Text vertical alignment in WPF TextBlock

A Textblock itself can’t do vertical alignment The best way to do this that I’ve found is to put the textblock inside a border, so the border does the alignment for you. <Border BorderBrush=”{x:Null}” Height=”50″> <TextBlock TextWrapping=”Wrap” Text=”Some Text” VerticalAlignment=”Center”/> </Border> Note: This is functionally equivalent to using a grid, it just depends how you … Read more

Difference between Label and TextBlock

TextBlock is not a control Even though TextBlock lives in the System.Windows.Controls namespace, it is not a control. It derives directly from FrameworkElement. Label, on the other hand, derives from ContentControl. This means that Label can: Be given a custom control template (via the Template property). Display data other than just a string (via the … Read more

How to bind a TextBlock to a resource containing formatted text?

Here is my modified code for recursively format text. It handles Bold, Italic, Underline and LineBreak but can easily be extended to support more (modify the switch statement). public static class MyBehavior { public static string GetFormattedText(DependencyObject obj) { return (string)obj.GetValue(FormattedTextProperty); } public static void SetFormattedText(DependencyObject obj, string value) { obj.SetValue(FormattedTextProperty, value); } public static … Read more

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