如何在WPF中将文本框文本设置为超链接 [英] how to make Textbox text as Hyperlink in WPF

查看:329
本文介绍了如何在WPF中将文本框文本设置为超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0下来投票最爱





我想将文本框文本设为超链接。假设我输入www.google.com作为tetxbox文本,当我点击文本时,它会显示在浏览器中打开链接..



我无法获得任何想法实现这个......你能不能建议我......我试过两种方式。



way1:

< pre lang =HTML> < TextBox Grid.Row = 4 名称 = txtWebPage VerticalAlignment = Top TextDecorations = Un derLine TextChanged = txtWebPage_TextChanged 前景 = 蓝色 >
< / TextBox >





way2:



< pre lang =HTML > 
< RichTextBox Grid.Row =4Name =rtxtWebBorderBrush =GrayBorderThickness =1VerticalAlignment =TopHeight =20IsDocumentEnabled =TrueForeground =BlueLostFocus = rtxtWeb_LostFocus >
< FlowDocument>
<段落>
< Hyperlink NavigateUri =/>
< /段落>
< / FlowDocument>
< / RichTextBox>



我无法获得如何将RichTextBox文本绑定到Hyperlink uri! richtextbox没有点击事件...任何建议请...

解决方案

您好


您可以使用IsMouseCaptureWithinChanged TextBox的事件,只要你点击TextBox就会命中。


0 down vote favorite


I want to make textbox text as Hyperlink. Suppose if i type www.google.com as tetxbox text,when i click on the text ,it show open the link in a browser..

I could not get any idea to implement this...can u suggest me any idea...i tried the two ways.

way1:

<TextBox Grid.Row="4" Name="txtWebPage" VerticalAlignment="Top" TextDecorations="UnderLine" TextChanged="txtWebPage_TextChanged" Foreground="Blue">
                                </TextBox>



way2:

<pre lang="HTML">
<RichTextBox Grid.Row="4" Name="rtxtWeb" BorderBrush="Gray" BorderThickness="1" VerticalAlignment="Top" Height="20" IsDocumentEnabled="True" Foreground="Blue" LostFocus="rtxtWeb_LostFocus">
                                    <FlowDocument>
                                        <Paragraph>
                                            <Hyperlink NavigateUri=""/>
                                        </Paragraph>
                                    </FlowDocument>
                                </RichTextBox>


I couldnt get how can i bind the RichTextBox text to Hyperlink uri!!! There is no click event for richtextbox...any suggestion please...

解决方案

Hi
You can use IsMouseCaptureWithinChanged event for TextBox, It will hit whenever you click on TextBox.


这篇关于如何在WPF中将文本框文本设置为超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆