2013-11-20 69 views
2

这里是我的代码:如何用文字添加超链接的文本框中

<TextBlock TextWrapping="Wrap" TextAlignment="Left"> 
    <TextBox IsReadOnly="True" BorderThickness="0" TextWrapping="Wrap">  
     Please enter your details for login: questions follow the link 
    </TextBox> 
    <Hyperlink NavigateUri="https:" RequestNavigate="Hyperlink_RequestNavigate"> 
     Reset Password 
    </Hyperlink> 
</TextBlock> 

文本框不会让我设置文本超链接。我需要将超链接保留在文本框之外,这会创建一个新行。但我希望超链接串联到文本。

我在TextBlock中使用TextBox的原因是为了使文本可选。

回答

4

我建议溶液采用单RichTextBox

<RichTextBox IsReadOnly="True" IsDocumentEnabled="True" > 
     <FlowDocument> 
      <Paragraph> 
       Please enter your details for login: questions follow the link 
       <Hyperlink NavigateUri="https:" RequestNavigate="Hyperlink_RequestNavigate">Reset Password</Hyperlink> 
      </Paragraph> 
     </FlowDocument> 
    </RichTextBox> 
0

如果你用StackPanel替换你的外部TextBlock,它是否实现你想要的?

<StackPanel Orientation="Horizontal"> 
    <TextBox VerticalAlignment="Center" IsReadOnly="True" BorderThickness="0" TextWrapping="Wrap"> 
     Please enter your details for login: questions follow the link 
    </TextBox> 
    <TextBlock VerticalAlignment="Center"> 
     <Hyperlink NavigateUri="https:" RequestNavigate="Hyperlink_RequestNavigate"> 
      Reset Password 
     </Hyperlink>  
    </TextBlock> 
</StackPanel> 
+0

因为上面堆叠面板水平地对准元件它不会达到要求。我有窗口大小问题,所以文本和超链接应该进入新行。 – user1118468

+0

@ user1118468然后设置StackPanel Orientation =“Vertical” – Kcvin

相关问题