1.-------------------------------------------------------------------------
To modify the text of a hyperlink:
<TextBlock><Hyperlink>
<textblock x:name= "Textblockneedchange" text= "changed text"/>
</Hyperlink></TextBlock>
Modify textblockneedchange.text= "xxxxx" can be;
2.-----------------------------------------------------------------------
Text: Hyperlinks in TextBlock text dynamically updated in WPF
In the writing of small software when suddenly need to display the text dynamic update, and then there is a hyperlink, in the ordinary WinForm inside good
Like a linklabel, but WPF did not find, anyway, see there is a TextBlock to add hyperlinks in the example, the attempt was changed, but for
Hyperlinks update never find a good way, accidentally turned on MSDN to find their own needs of the example, now recorded to facilitate their own later to view
The
In the WPF project, you'll first add TextBlock controls and hyperlinks through XAML, and then dynamically update the text in the control program
and hyperlink content, unfortunately has not yet reached the dynamic increase in the number of hyperlinks, not to try, it should also be possible.
(1) Adding TextBlock controls and hyperlinks through XAML
A grid container in a WPF form divides the TextBlock into a position and then drags it into the control, following the code that is picked out
<textblock name= "Navigatetextblock"
Margin= "14,0,0,5" grid.row= "1"
Textwrapping= "Wrap"
foreground= "Yellow" >
<linebreak ></LineBreak>
</TextBlock>
This displays "Hyperlink www.qq.com" in the form, pointing to the address www.qq.com. There is no need to say the color and the divider line.
(2) Dynamically update text and hyperlink content in the control program
In the control program to dynamically update the text is very simple, navigatetextblock.text= "", you can set the required text;
Updating hyperlinks is a bit of a hassle, but as long as you're familiar with the hyperlink class, it's easy. In MSDN for the hyperlink class there are the following
Example code:
Paragraph Parx = new Paragraph ();
Run run1 = new Run ("Text preceeding the Hyperlink.");
Run run2 = new Run ("Text following the hyperlink.");
Run RUN3 = new Run ("Link Text.");
Hyperlink Hyperl = new Hyperlink (RUN3);
Hyperl. NavigateUri = new Uri ("http://search.msn.com");
Parx. Inlines.add (RUN1);
Parx. Inlines.add (Hyperl);
Parx. Inlines.add (RUN2);
You can see the use of this class, so you can modify the Hyperlink object in TextBlock in this way to update it, as follows
Run Runtexttemp=new run (text);
HpHost.Inlines.Clear ();
HPHOST.INLINES.ADD (runtexttemp);
Hphost.navigateuri = new Uri (hplink);
After writing the discovery is really simple, but they are not very familiar with these, the first use are now looking, now learn to use. In fact, initially, I only
is to directly through the frame class to display the Web page, and later because of their own variable form, resulting in the page does not display properly, so have to
Extracts text and hyperlinks to display.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hyperlinks in TextBlock text are dynamically updated in WPF, text