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

Bug in RadTextBox

2 Answers 63 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vladimir
Top achievements
Rank 1
Vladimir asked on 20 Jan 2013, 12:00 PM
Hi there,

I found a bug in RadTextBox, namely
if I clear the Text in RadTextBox by using the "X" clear button and then later assign the DataContext Property the RadTextBox does nothing... it still has an empty text inside.
I've have a demo project:
The Version of Telerik Controls: 2012.3.1211.3040
Test Scenario:
  1. Open App.
  2. Tap button
  3. Clear text by using the "X" button.
  4. Tap Button again.
  5. Expected result: Text in RadTextBox
  6. Actual Result: Text is empty.

As you can see the standart WP8 TextBox handles DataContext_Changed event and displays the text.

I have,
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">           
            <controls:RadTextBox Text="{Binding Text}" Height="100" Name="tnText"></controls:RadTextBox>
            <Button Click="ButtonBase_OnClick" Height="78">Set Data Context</Button>
            <TextBox Text="{Binding Text}" Height="72" TextWrapping="Wrap" />
 
        </StackPanel>

ViewModel
public class ViewModel : INotifyPropertyChanged
    {
        private string _text;
        public string Text
        {
            get { return _text; }
            set
            {
                _text = value;
                OnPropertyChanged();
            }
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

and button click event:
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            this.DataContext = new ViewModel
            {
                Text = "13222"
            };
        }

best regards,
Vladimir.

2 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 21 Jan 2013, 07:29 AM
Hi Vladimir,

Thank you for contacting us.

The reason for this behavior is that when you press the clear button, the TextProperty is set to string.Empty and the binding is removed. The workaround is to set the binding to be two way:
<controls:RadTextBox Text="{Binding Text, Mode=TwoWay}" Height="100" Name="tnText"></controls:RadTextBox>

If this is not acceptable, please elaborate a bit more about your scenario and why would you need a one way binding to a property of a view model and also enable editing of the text box.

All the best,
Todor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Vladimir
Top achievements
Rank 1
answered on 21 Jan 2013, 08:18 AM
Hi Todor ,

Thank you for the responce. I'll try it later today. 

best regards,
Vladimir.
Tags
TextBox
Asked by
Vladimir
Top achievements
Rank 1
Answers by
Todor
Telerik team
Vladimir
Top achievements
Rank 1
Share this question
or