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

SearchText not Updated

3 Answers 190 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 08 Mar 2018, 01:52 PM

I have a RadAutoCompleteBox:

 

<telerik:RadAutoCompleteBox x:Name="CustomerAutoCompleteBox" Grid.Row="10" Grid.Column="1" Margin="3"
    IsEnabled="{Binding IsReadOnly, Converter={StaticResource InvertedBooleanConverter}}"
    ItemsSource="{Binding Occurrence.Appointment.AllCustomerResourceTypesForDialog, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    SearchText="{Binding Occurrence.Appointment.AllCustomerResourceTypesSearchText, BindsDirectlyToSource=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    SelectedItem="{Binding Occurrence.Appointment.Customer, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    IsDropDownOpen="{Binding Occurrence.Appointment.IsCustomerDropDownOpen, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    SelectionMode="Single"
    DisplayMemberPath="DisplayName"
    TextSearchPath="DisplayName"
    MinWidth="218" >
</telerik:RadAutoCompleteBox>

 

The Appointment which is Bound is Created and filled with data like this:

var telerikAppointment = new ExtendedAppointment();
var customerResource = new Resource
                {
                    DisplayName = ((ModelsPath.Customer)appointment.Models[0]).KUNAM1.Trim(),
                    ResourceName = ((ModelsPath.Customer)appointment.Models[0]).CustomerId.ToString().Trim(),
                    ResourceType = Application.Current.FindResource("ResourceName.Customer") as string
                };
 
 
                telerikAppointment.AllCustomerResourceTypesForDialog.Clear();
                telerikAppointment.AllCustomerResourceTypesForDialog.Add(customerResource);
                telerikAppointment.Customer = customerResource;

 

Not my problem is, that the AllCustomerResourceTypesSearchText Property is not Updated when i start the AutoCompleteBox with a CustomerResource in it. When i tyoe some Text in it now to Search for another one the AllCustomerResourceTypesSearchText is not updaten and then my application is not searching for more Customers in the Database.

 

It Works fine if i start the RadBox without a pre selected Customer and AllCustomerResourceTypesForDialog and then try to search

 

Customer is a Resource and AllCustomerResourceTypesForDialog is a ObservableCollection<Resource>

 

I dont know how to fix this Problem so the bound AllCustomerResourceTypesSearchText Property is always updated.

 

 

3 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 13 Mar 2018, 12:33 PM
Hello Kevin,

Thank you for the provided code. 

My understanding is that the property bound to the SearchText property of the RadAutoCompleteBox is not updated when you type in the RadAutoCompleteBox. Feel free to correct me if I am wrong in my understanding and provide some more information about the described scenario. 

That said I was unable to reproduce this behavior on my side. That is why I am attaching the sample project that I used. May I ask you to take a look at it and see how it differs from the setup at your end? Should you need further assistance, may I ask you to modify the attached project in order to reproduce the described behavior and send it back? This way I will be able to test it on my side and better assist you.

I am looking forward to your reply.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Kevin
Top achievements
Rank 1
answered on 14 Mar 2018, 08:02 AM

Our scenario is a litte different. We have a ScheduleView with ExtendedAppointment and in this Appointments we have a Observable Collection<Customer> (ItemSource of AutoComplereBox) and a object Customer (SelectedItem of AutoCompleteBox).

We have a Custom EditAppointmentDialogStyle and in this there is the AutoCompleteBox.

 

Now when we have a Appointment in the ScheduleView and opening the Edit Appointment Dialog and write the Text in the AutoCompleteBox the Setter of the bound Property in ExtendedAppointment is never called. If we create a new Appointment without pre Selected Customer it works fine.

 

We Provided a litte Example Solution to show the Problem.

Try to open the Appointment which is in ScheduleView on Startup and edit the Customer in AutoCompleteBox and no Setter of Searchtext is called.

 

Try it on a new Appointment and the Setter is called.

 

Can you help us with that Problem?

We need se Setter of the SearchText because in out Real Application we want to Search in out Database for Customers when SearchText changes. It works on new Appointments but not on already filled ones with Customer.

 

To open the test Solution you have to rename the File from test.jpg to test.zip

0
Vladimir Stoyanov
Telerik team
answered on 16 Mar 2018, 02:36 PM
Hello Kevin,

Thank you for the provided information and the project.

While I am uncertain as to the exact cause of the problem, it seems that the SearchText binding is not evaluated correctly initially. What I can suggest is to create an attached behavior which will set the binding in the Loaded event of the RadAutoCompleteBox. Here is how that would look:
public class ShouldUpdateSearchTextBindingBehavior
    {
        public static bool GetShouldUpdateSearchTextBinding(DependencyObject obj)
        {
            return (bool)obj.GetValue(ShouldShowConfirmationDialogProperty);
        }
 
        public static void SetShouldUpdateSearchTextBinding(DependencyObject obj, bool value)
        {
            obj.SetValue(ShouldShowConfirmationDialogProperty, value);
        }
 
        public static readonly DependencyProperty ShouldShowConfirmationDialogProperty =
            DependencyProperty.RegisterAttached("ShouldUpdateSearchTextBinding", typeof(bool), typeof(ShouldUpdateSearchTextBindingBehavior), new PropertyMetadata(OnShouldUpdateSearchTextBindingChanged));
 
        private static void OnShouldUpdateSearchTextBindingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var autoComplete = d as RadAutoCompleteBox;
 
            autoComplete.Loaded += AutoComplete_Loaded;
        }
 
        private static void AutoComplete_Loaded(object sender, RoutedEventArgs e)
        {
            var binding = new Binding() { Path = new System.Windows.PropertyPath("Occurrence.Appointment.CustomerSearchText"), BindsDirectlyToSource = true, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay };
            var autoComplete = (sender as RadAutoCompleteBox);
            autoComplete.SetBinding(RadAutoCompleteBox.SearchTextProperty, binding);
        }
    }

Then you would need to set this property on the RadAutoCompleteBox like so:
<telerik:RadAutoCompleteBox Grid.Row="9" Grid.Column="1" Margin="3"
                                            IsEnabled="{Binding IsReadOnly, Converter={StaticResource InvertedBooleanConverter}}"
                                            ItemsSource="{Binding Occurrence.Appointment.AllCustomerResources, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                                            SelectedItem="{Binding Occurrence.Appointment.Customer, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                                            local:ShouldUpdateSearchTextBindingBehavior.ShouldUpdateSearchTextBinding="True"
                                            DisplayMemberPath="Name"   
                                            SelectionMode="Single"    
                                            MinWidth="218"
                                             />

Please give this approach a try and let me know if it is suitable for your scenario.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
AutoCompleteBox
Asked by
Kevin
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or