How to get selected text from non-editable text field in silverlight for wp7

I want to have a text box with text that the user can select but not edit, and I want to perform some operations on this text.

I create a text box and set IsReadOnly = "True". When I click on some text, I see that it is highlighted, but when the SelectionChanged event fires, textBox1.SelectedText is empty.

When IsReadOnly = "False", it works, but the keyboard pops up, which I don't want. Does anyone know how to achieve what I want? Any help would be appreciated.

+3
source share
3 answers

( , ), , , App Hub. TextBox.IsReadOnly: " , , . , . KeyUp KeyDown ." , SelectedText ( SelectionStart SelectionLength, 0 ).

, , TextBox, , IsReadOnly false, SelectedText, SelectionStart SelectionLength . .

+2

Text TextBox, , . - TextBoxName.Attributes.Add( "", "SomeText" );

+1

, , SelectionChanged ReadOnly, .SelectionStart .SelectionLength 0.

, . , xaml , , . , , read-only, IsReadOnly = True, SelectionChanged, Textbox read-write.

, -, , , , IsReadOnly True reports.SelectionStart .SelectionLength .

, Textbox.Template.

<ControlTemplate TargetType="TextBox">
    <Grid
        Margin="{TemplateBinding Margin}"
        Background="Transparent">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal"/>
                <VisualState x:Name="MouseOver"/>
                <VisualState x:Name="Disabled" />
                <VisualState x:Name="ReadOnly" />
            </VisualStateGroup>
            <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Focused"/>
                <VisualState x:Name="Unfocused"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Border
            Background="{TemplateBinding Background}"
            Margin="0">
            <ContentControl 
                x:Name="ContentElement" 
                BorderThickness="0" 
                Margin="{StaticResource PhoneTextBoxInnerMargin}" 
                Padding="{TemplateBinding Padding}" 
                HorizontalContentAlignment="Stretch" 
                VerticalContentAlignment="Stretch" 
                Foreground="{TemplateBinding Foreground}"/>
        </Border>
    </Grid>
</ControlTemplate>
+1
source

Source: https://habr.com/ru/post/1786565/