AutoCompleteBox SelectedItems Binding problem

19 posts, 0 answers
  1. Marcelo
    Marcelo avatar
    8 posts
    Member since:
    Apr 2012

    Posted 14 Feb 2013 Link to this post

    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

  2. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 20 Feb 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Marcelo
    Marcelo avatar
    8 posts
    Member since:
    Apr 2012

    Posted 20 Feb 2013 Link to this post

    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
  5. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 26 Feb 2013 Link to this post

    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.

  6. Marcelo
    Marcelo avatar
    8 posts
    Member since:
    Apr 2012

    Posted 26 Feb 2013 Link to this post

    Hi Ivo,

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

    Marcelo Bateira
  7. Hadar
    Hadar avatar
    3 posts
    Member since:
    Feb 2013

    Posted 23 May 2013 Link to this post

    Hi,

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

    Thanks.
  8. Hadar
    Hadar avatar
    3 posts
    Member since:
    Feb 2013

    Posted 23 May 2013 Link to this post

    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>());
            }
  9. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 23 May 2013 Link to this post

    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.

  10. Hadar
    Hadar avatar
    3 posts
    Member since:
    Feb 2013

    Posted 23 May 2013 Link to this post

    Hi Ivo,

    I'm using V 2013.1.403.40.

    my code is in a DataTemplate resides in a ContentControl.

    Thanks,
    Hadar.

  11. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 28 May 2013 Link to this post

    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.

  12. Cecile
    Cecile avatar
    10 posts
    Member since:
    Jul 2010

    Posted 11 Oct 2013 Link to this post

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

    Posted 11 Oct 2013 Link to this post

    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 >>
  14. Stefan
    Stefan avatar
    5 posts
    Member since:
    Mar 2014

    Posted 03 Aug Link to this post

    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

  15. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 05 Aug Link to this post

    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.
  16. Stefan
    Stefan avatar
    5 posts
    Member since:
    Mar 2014

    Posted 05 Aug Link to this post

    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

  17. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 10 Aug Link to this post

    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.
  18. Stefan
    Stefan avatar
    5 posts
    Member since:
    Mar 2014

    Posted 10 Aug in reply to Yana Link to this post

    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

  19. Stefan
    Stefan avatar
    5 posts
    Member since:
    Mar 2014

    Posted 10 Aug in reply to Stefan Link to this post

    Hello Yana,

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

    Thanks,
    Stefan
  20. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 12 Aug Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready