dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.02k stars 1.16k forks source link

Text selection for TextBlock #307

Open h82258652 opened 5 years ago

h82258652 commented 5 years ago

This feature is already exist in UWP, can it port to WPF?

karelz commented 5 years ago

AFAIK the code bases are vastly different, so "porting" means writing it from scratch ... just FYI.

vatsan-madhavan commented 5 years ago

Related: SO discussion

h82258652 commented 5 years ago

@vatsan-madhavan But HorizontalAlignment does not work for RichTextBox, even the text is very short.

<TextBlock HorizontalAlignment="Right">
</TextBlock><!-- of course, this is ok -->
<RichTextBox IsReadOnly="True"
             HorizontalAlignment="Right">
</RichTextBox><!-- this does not work -->

In my project, I'm using this way to solve.

<Grid HorizontalAlignment="Right">
    <TextBlock x:Name="TextBlock"
               IsHitTestVisible="False"
               Opacity="0"
               TextWrapping="Wrap" />
    <RichTextBox Width="{Binding Element=TextBlock, Path=ActualWidth}"
                 IsReadOnly="True" />
</Grid>

But I think it is too complex, I hope it will be simpler.

Red6789 commented 1 year ago

Since RichTextbox does not support automatic width and height, I also solved it like you, and I hope Microsoft will pay attention to this problem sooner