RadWatermarkTextBox - CurrentText vs Text - which to use?

6 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 28 Jan 2011 Link to this post

    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>

  2. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 28 Jan 2011 Link to this post

    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>


  3. DevCraft banner
  4. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 01 Feb 2011 Link to this post

    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>>
  5. jason
    jason avatar
    4 posts
    Member since:
    Jun 2011

    Posted 17 Jun 2011 Link to this post

    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.  
  6. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 23 Jun 2011 Link to this post

    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
  7. James
    James avatar
    26 posts
    Member since:
    Oct 2008

    Posted 03 Apr 2012 Link to this post

    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

Back to Top
DevCraft banner