June 23, 2009 15:16
The Silverlight Control Toolkit's Hyperlink Button is a nice little control. But almost immediately I ran into one of its shortcomings: it doesn't support text wrapping.
Fortunately, this can be solved pretty easily.
Just wrap a TextBlock inside the HyperlinkButton control.
In XAML, it looks like:
1: <HyperlinkButton NavigateUri="http://www.itscodingtime.com">
2: <TextBlock Text="this text will wrap" TextWrapping="Wrap" />
3: </HyperlinkButton>
In C# code:
1: var textBlock = new TextBlock { Text = "this text will wrap", TextWrapping = TextWrapping.Wrap };
2:
3: var lnkBtn = new HyperlinkButton
4: {
5: Content = textBlock,
6: };
7:
8: uxWrapPanel.Children.Add (lnkBtn);
I create a new TextBlock, initializing it with some text and the TextWrapping property set to "Wrap". Next, add it as the Content property in a new HyperlinkButton. Last, I add it to a WrapPanel, which is the context in which I am working in.
That's it.