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

AutoCompleteBox SelectedItems Binding problem

18 Answers 764 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Marcelo
Top achievements
Rank 1
Marcelo asked on 14 Feb 2013, 03:18 PM
Hi,

I have a Listbox with a datatemplate:
<DataTemplate x:Key="ListBoxDataTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding FieldName, Mode=TwoWay}" Width="120" />
                <telerik:RadAutoCompleteBox Width="197" Name="autoCompBox"
                        Background="Beige" SelectionMode="Multiple" TextSearchMode="StartsWith"
                        TextSearchPath="Code" AutoCompleteMode="Suggest"
                        DropDownItemTemplate="{StaticResource ContactSearchTemplate}" DataContext="{Binding}"
                        ItemsSource="{Binding DataContext.Codes, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=telerik:RadListBox}}"
                        SelectedItems="{Binding Path=AssociatedCodes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                </telerik:RadAutoCompleteBox>
            </StackPanel>
        </DataTemplate>
My ListBox ItemsSource property is binded to a property in ViewModel named:
public List<ReportDataAssociation> ReportDataAssociation
        {
            get { return m_reportDataAssociation; }
            set { m_reportDataAssociation = value; OnPropertyChanged("ReportDataAssociation"); }
        }

This property is an object with the following properties:
string FieldName;
ObservableCollection<ReportCodes> AssociatedCodes;
The FieldName is binded to the TextBlock
The AssociatedCodes is binded to the SelectedItemsProperty of each AutoCompleteBox.

I load an ObservableCollection<ReportCodes> named Codes which is binded to all AutoCompleteBoxes.
The AssociatedCodes is a property of ReportDataAssociation which is binded to SelectedItems.
Any ReportCode I add to the AssociatedCodes' List is from the ObservableCollection<ReportCodes> named Codes
so the referece to the object is the same.

The problem is:
When I select or delete some items from some autocompletebox,
the property AssociatedCodes does not change.
When I change the property AssociatedCodes at runtime, the selectedItems in autocompletebox
don't change.
I think it's a binding problem but i can't figure out what it is.
Maybe because the AutoCompleteBoxes are in a template.

I tried to bind the selectedItems in many ways, the binding shown above is one of my many tries..
Please help
Thanx in advance

18 Answers, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 20 Feb 2013, 01:54 PM
Hi Marcelo,

We investigated this and found out it was an issue with RadAutoCompleteBox. The issue appears only when the control is placed in DataTemplate in ItemsControl. A fix for it should be available in the next couple of weeks.

Thank you for your great feedback!

Greetings,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marcelo
Top achievements
Rank 1
answered on 20 Feb 2013, 02:19 PM
Thank you for your feedback.

I had to change the MVVM concept for this form in particular.

Let me know when the fix is avaiable.

Greetings,
Marcelo Bateira
0
Ivo
Telerik team
answered on 26 Feb 2013, 07:18 AM
Hi Marcelo,

The fix for this should be included into the latest internal build. It would be great if you test it and confirm that it is fixed on your side.

Greetings,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marcelo
Top achievements
Rank 1
answered on 26 Feb 2013, 09:02 AM
Hi Ivo,

when the build is done, as soon as I can I'll test it

Marcelo Bateira
0
Hadar
Top achievements
Rank 1
answered on 23 May 2013, 07:02 AM
Hi,

I encountered with the same issue. Is this fix already available? 
If not please help with a different solution in the meanwhile.

Thanks.
0
Hadar
Top achievements
Rank 1
answered on 23 May 2013, 08:02 AM
Hi again,

I bypass the issue using  blend.

in the XAML:
 <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                            <i:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
                                       CommandParameter="{Binding SelectedItems, ElementName=elementsCompleteBox}"/>
                        </i:EventTrigger>
 </i:Interaction.Triggers>

and in the VM:
      public ICommand SelectionChangedCommand { get; set; }
     SelectionChangedCommand = new DelegateCommand<ObservableCollection<object>>(UpdateMultiSelect);

  private void UpdateMultiSelect(ObservableCollection<object> objects)
        {
            myModelListSelected = new ObservableCollection<myModel>(objects.Cast<myModel>());
        }
0
Ivo
Telerik team
answered on 23 May 2013, 08:22 AM
Hi Hadar,

Can you specify what version do you use? A fix for this issue was included into the Q1 SP1 2013 version of RadControls for WPF.

Regards,
Ivo
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Hadar
Top achievements
Rank 1
answered on 23 May 2013, 08:48 AM
Hi Ivo,

I'm using V 2013.1.403.40.

my code is in a DataTemplate resides in a ContentControl.

Thanks,
Hadar.

0
Ivo
Telerik team
answered on 28 May 2013, 01:37 PM
Hi Hadar,

It seems we introduced this issue once again after it was fixed. A fix for this issue would be available for the first internal build after the Q2 release.

Regards,
Ivo
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Cecile
Top achievements
Rank 1
answered on 11 Oct 2013, 05:20 AM
Hi,
has this issue been fixed?
I'm using RadControls_for_WPF_2013_2_1007_DEV_hotfix and the issue seems to still exist.

Thanks,
Olivier.
0
Yana
Telerik team
answered on 11 Oct 2013, 02:44 PM
Hello Olivier,

We did not manage to reproduce the issue with the latest internal build, could you please send us a sample project demonstrating the exact problem you're experiencing? You should open a support ticket and attach it there.

Thanks in advance

Regards,
Yana
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Stefan
Top achievements
Rank 1
answered on 03 Aug 2016, 10:12 AM

Hi,

 

I am using version 2016.2.613.45 and the issue is still there.

 

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=SelectedItems; DataItem='RadAutoCompleteBox' (Name=''); target element is 'AddItemAdapterCollection' (HashCode=3396431); target property is 'Source' (type 'IEnumerable')

Any hope to get this fixed anytime?

 

Thanks,

Stefan

0
Yana
Telerik team
answered on 05 Aug 2016, 01:40 PM
Hi Stefan,

I'd ask you to open a support ticket and send us a simple project showing the exact scenario you have, so we to be able to reproduce the error and provide proper assistance.

Thank you in advance.

Regards,
Yana
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Stefan
Top achievements
Rank 1
answered on 05 Aug 2016, 03:33 PM

Hi Yana,

it was not my intention to become a Telerik Bug-Expert. Since this is a very basic scenario i'm sure you will find someone who will agree to code a repro for you.

Environment:
Visual Studio 2015 with Update 3
.NET 4.5
- Telerik WPF Controls 2016.2.613.45.NoXaml

Conditions:
- RadAutoCompleteBox was placed inside a TabControl
- SelectedItems Binding to an ObservableCollection<object>

As soon as you switch tabs and come back to the tab where the RadAutoCompletBox is located the VS debug out will show the error.

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=SelectedItems; DataItem='RadAutoCompleteBox' (Name=''); target element is 'AddItemAdapterCollection' (HashCode=19355258); target property is 'Source' (type 'IEnumerable')

 Thanks,
Stefan

0
Yana
Telerik team
answered on 10 Aug 2016, 07:32 AM
Hello Stefan,

I am sorry for my misunderstanding.

Actually this is a known error related to a timing issue in WPF platform. More information can be found in the official social MSDN forums here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/564e7160-df70-4e95-945d-60954dd7a2ae/wpf-binding-errors-systemwindowsdata-error-4?forum=wpf

Such issues should be ignored as they are timing issues in the WPF platform itself and are not critical for runtime. If you would like not to see them in the output after building your project you could use the following workaround:
- In your project's code behind set the DataBindingSource.Switch.Level to Critical. The next code snippet shows the described workaround:
System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;

You could also set IsContentPreserved property of RadTabControl to true, so that the content is not reloaded every time you switch the tabs.

Regards,
Yana
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Stefan
Top achievements
Rank 1
answered on 10 Aug 2016, 07:39 AM

Hello Yana,

 

thanks for your reply.

However, if this would be a timing issue the RadAutoCompleteBox is even more broken as the control is fully rendered and no items are changed. So what does RadAutoCompletBox do? Does it refresh item lists on getting focus? I hope not! Are you sure you are handling UI rendering correctly?

Thanks,
Stefan

0
Stefan
Top achievements
Rank 1
answered on 10 Aug 2016, 07:42 AM
Hello Yana,

just to mention: I'm not using the RadTabcontrol. It's the standard WPF TabControl.

Thanks,
Stefan
0
Yana
Telerik team
answered on 12 Aug 2016, 02:16 PM
Hi Stefan,

Again, I apologize for the confusion.

The observed behavior is reproducible when the AutoCompleteBox is placed inside the native WPF TabControl. The control is reloading its content each time when the tabs are switching. Because of that the elements from the previously selected tab get removed from the Visual Tree and the one from the newly selected are loaded - the observed error is a timing issue that gets resolved.

What we could suggest you is instead of using the native WPF TabControl to use the one provided by Telerik RadTabControl. It provides a property named IsContentPreserved that by setting it to True prevents the controls from removing from the Visual Tree when switching between the Tabs and the bindings are preserved.

Regards,
Yana
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
AutoCompleteBox
Asked by
Marcelo
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Marcelo
Top achievements
Rank 1
Hadar
Top achievements
Rank 1
Cecile
Top achievements
Rank 1
Yana
Telerik team
Stefan
Top achievements
Rank 1
Share this question
or