This is a migrated thread and some comments may be shown as answers.

RadWatermarkTextBox - CurrentText vs Text - which to use?

5 Answers 511 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 28 Jan 2011, 03:09 PM
Hello,

I'm trying to understand the difference between the "CurrentText" and "Text" properties of the RadWatermarkTextBox control.  Which property should I bind my data object to?  One or the other or both?

I thought it made sense that when I was typing in the textbox, the "CurrentText" property was updated with each character entered, but the "Text" property was not actually updated until the textbox lost focus.  But for a small demo project I put together, it doesn't seem to matter...  As I type in the textbox, it looks like both the "Text" and "CurrentText" property are updated.

<Grid>
      
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
        </Grid.RowDefinitions>
          
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
          
        <StackPanel Grid.Row="0" Grid.Column="0" Background="Pink">
          
            <Border Padding="3">
                <telerik:RadWatermarkTextBox x:Name="tb1" Text="Text" CurrentText="CurrentText" WatermarkContent="WatermarkContent" />
            </Border>
  
        </StackPanel>
  
          
        <StackPanel Grid.Row="0" Grid.Column="1" Background="White">
          
            <Border Padding="3">
                <TextBlock Text="{Binding ElementName=tb1, Path=Text, StringFormat='@Text=\{0\}'}" />
            </Border>
              
            <Border Padding="3">
                <TextBlock Text="{Binding ElementName=tb1, Path=CurrentText, StringFormat='@CurrentText=\{0\}'}" />
            </Border>
              
            <Border Padding="3">
                <TextBlock Text="{Binding ElementName=tb1, Path=WatermarkContent, StringFormat='@WatermarkContent=\{0\}'}" />
            </Border>
  
        </StackPanel>
  
    </Grid>

5 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 28 Jan 2011, 03:42 PM
Hello again,

Actually, I think I have discovered a problem with the RadWatermarkTextBox that was causing my confusion...

If you hardcode the "Text" property of a RadWatermarkTextBox, instead of binding it, the initial value of "CurrentText" is null until you actually manipulate it.  And there must be some sort of link between that the Watermark.  If you load this application, and put focus into the "ReadOnly" field simply by clicking on it, look what happens to the first RadWatermarkTextBox - it shows both the watermark and the text because there is no current text...

<Grid>
      
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
        </Grid.RowDefinitions>
          
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
          
        <StackPanel Grid.Row="0" Grid.Column="0" Background="Pink">
          
            <Border Padding="3">
                <telerik:RadWatermarkTextBox x:Name="tb1" Text="Normal" WatermarkContent="WatermarkContent" />
            </Border>
  
            <Border Padding="3">
                <telerik:RadWatermarkTextBox x:Name="tb2" Text="IsEnabled='False'" IsEnabled="False" WatermarkContent="WatermarkContent">
            </Border>
  
            <Border Padding="3">
                <telerik:RadWatermarkTextBox x:Name="tb3" Text="IsReadOnly='True'" IsReadOnly="True" WatermarkContent="WatermarkContent"/>
            </Border>
  
            <Border Padding="3">
                <telerik:RadWatermarkTextBox x:Name="tb4" Text="IsReadOnly='True' AND IsEnabled='False'" IsEnabled="False" IsReadOnly="True" WatermarkContent="WatermarkContent"/>
            </Border>
  
        </StackPanel>
  
    </Grid>


0
Alex Fidanov
Telerik team
answered on 01 Feb 2011, 04:10 PM
Hello Rob,

The CurrentText property is meant to be used (to be boundbound) in TwoWay-binding scenarios so that it is updated on each change of the text and not when the control loses focus (the value is updated in the TextChanged event of the textbox).


Regards,
Alex Fidanov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
jason
Top achievements
Rank 1
answered on 17 Jun 2011, 07:23 PM
I'm finding the RadWatermarkTextBox to be very frustrating.  I'm getting the same behavior the first post referred to when binding the text property.  Both the text and the watermark show up when the textbox receives focus and then loses focus without making any changes.  If I try to bind the currenttext property as suggested the text just goes away, never to return, when the control receives focus.  
0
Yana
Telerik team
answered on 23 Jun 2011, 09:16 AM
Hi Jason,

I've tried to reproduce this issue but without much success - CurrentText property is bound and updated as expected. Please check the attached simple project.

All the best,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
James
Top achievements
Rank 1
answered on 03 Apr 2012, 05:37 AM
Thanks heaps, this helped alot.

If you guys could show this as example in demo app, that would have been quick to look at solution.
CurrentText="{Binding Path=Value, Mode=TwoWay}" Text="{Binding Path=Value, Mode=OneTime}"

 

That is what I am doing, and that fixed the issue "Binding only updates value when control loses focus"

Thanks,
Bhavin

Tags
General Discussions
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Alex Fidanov
Telerik team
jason
Top achievements
Rank 1
Yana
Telerik team
James
Top achievements
Rank 1
Share this question
or