0

I can not clean the text property of a TextBox when the user clicks inside it. The TextBox is inside a HierarchicalDataTemplate but the trigger doesn't work.

My code is as follows:

 <HierarchicalDataTemplate x:Key="FoldersTemplate"
                                  DataType="{x:Type vm:FolderViewModel}"
                                  ItemsSource="{Binding Children}">
            <Border>
                <Grid>
                    <TextBox>
                        <TextBox.Style>
                            <Style TargetType="{x:Type TextBox}">
                                <Setter Property="Text" Value="{Binding Name}" />
                                <Style.Triggers>
                                    <Trigger Property="IsEnabled" Value="False">
                                        <Setter Property="Text" Value="{x:Null}" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>                                
                        </TextBox.Style>
                    </TextBox>                        
                </Grid>
            </Border>
        </HierarchicalDataTemplate>

enter image description here

The action I would like to happen is that when the user clicks on the text, it disappears. How can I solve this?

Thanks a lot.

FraDamm
  • 41
  • 2
  • Instead of clearing the control, clear the ViewModel's property to which the control is bound. – CodingYoshi Dec 06 '18 at 17:16
  • 1
    Are you maybe looking for a [text box with watermark/hint text](https://stackoverflow.com/questions/833943/watermark-hint-text-placeholder-textbox)? – dymanoid Dec 06 '18 at 17:17
  • 1
    Why should `Property="IsEnabled" Value="False"` correspond to `when the user clicks inside it` ?? – Rand Random Dec 06 '18 at 17:41
  • @CodingYoshi How can I do it? this is MVVM – FraDamm Dec 07 '18 at 11:42
  • @RandRandom sorry the code is wrong. I should intercept the mousedown event (or something like that) inside the textbox to make sure that if the user clicks in it the text disappears. – FraDamm Dec 07 '18 at 11:45
  • @dymanoid I can not insert other elements inside the template. The mechanism that binds the text property with "name" is very complex – FraDamm Dec 07 '18 at 11:46

0 Answers0