Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectableTextBlock ignores of text within InlineUIContainer - Suggestion #17239

Open
kuiperzone opened this issue Oct 10, 2024 · 0 comments
Open

Comments

@kuiperzone
Copy link

Is your feature request related to a problem? Please describe.

BACKGROUND
I'm trying to add a clickable styled link within SelectableTextBlock. First off, HyperLinkButton doesn't work for me because it has styling and padding which disrupts the flow of the text. I particularly wish to style the link myself. So I opted to derive a class from TextBlock and add it to the SelectableTextBlock via InlineUIContainer.

All well and good.

THE PROBLEM
The problem is that selecting text which includes an InlineUIContainer ignores the text within the container. Looking at the Avalonia code, it seems just to ignore it. I can't seem to override anything because all the required methods to do so are internal.

So when copied, the text in the screenshot below comes out as:

This is .

image
Forgive the olive background in the above. It's just for test. :)

Q. So, if there is a current way to do this which I'm missing, please do let me know????

Otherwise, I have a suggestion...

Describe the solution you'd like

If I could override InlineUIContainer.AppendText(), then the first thing I would try is this:

internal override void AppendText(StringBuilder stringBuilder)
{
    // OPTION 1
    // This way I can put any object I like in there and override its ToString() method
    stringBuilder.Append(Child.ToString());

    // OPTION 2
    // Or restrict to TextBlock...

    if (Child is TextBlock block)
    {
        stringBuilder.Append(block.Text);
    }
}

Additionally, or alternatively, I suggest to consider making InlineUIContainer.AppendText() protected scope so it can be extended.

Describe alternatives you've considered

Everything under the Sun, but I always run into an internal an method at the very end. :(

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant