I have this TextBox. This TextBox is located in DataTemplate:
<DataTemplate x:Key="myTemplate">
<TextBox Text="{Binding Path=FullValue, Mode=TwoWay}" IsEnabled="False" />
...
and I want to allow User to select the whole text inside it (optionally by clicking on the Textbox). And I don't want to use any code behind.
How to do that? Thanks in advance.
Using the IsReadOnly property instead of IsEnabled allows the user to select text. Also, if it shouldn't be edited, a OneWay binding should be enough.
The idea of XAML isn't to completely replace code-behind. Most important is that you try to have only UI-specific code in the code-behind, not business logic. That being said, selecting all text is UI-specific and doesn't hurt in the code-behind. Use myTextBox.SelectAll() for that.
One note I just discovered (obviously this is an old question but this might help someone):
If IsHitTestVisible=False
then selecting (and therefore Copy) is also disabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With