سؤال

Here is my code:

<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>

The textbox won't let me set the hyperlink in the text. I need to keep the hyperlink out of textbox, which creates a new line. But I want hyperlink tandem to the text.

My reason for using the TextBox inside the TextBlock is to make the text selectable.

هل كانت مفيدة؟

المحلول

I'd suggest solution utilising single 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>

نصائح أخرى

Does it achieve what you want if you replace your outer TextBlock with a StackPanel?

<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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top