Silverlight to WPF conversion Issue with AutoCompleteBox

Silverlight to WPF conversion Issue with AutoCompleteBox

Old forum URL: forums.lhotka.net/forums/t/12898.aspx


Jav posted on Wednesday, June 10, 2015

I am bringing my mature SL app to WPF. I am quite liberal with the use of AutoCompleteBoxes and often have more than one on a page.

The data for the dropdown of each Auto...box comes from a database table.  Instead of running to the Database for each Auto..box's list, I bring up the list for the whole page, and then use a subset of that list when the user navigates to a given Auto...box.  All my lists are of the MobileList kind.  This has worked fine in SL. (The same is happening with BusinessListBase)


In WPF the behavior is strange.  The lists do appear in the dropdown, but when I choose an item with mouse the selection immediately disappears and the box remains empty.  When I make the selection by using the up-down arrow keys on the keyboard, the selection behaves normally.


Now here is the interesting part.  If, instead of displaying the subset (Path = FilteredList), I use the entire list (Path = Model), everything works fine.  The workaround I have used on one instance of AutoCompleteBox is to create another class specifically to hold the selected subset.  Using that I can set the Path = Model, and with that things appear to work.  With the number Auto..boxses, making the change to all is, well, daunting.
So I thought I should ask if there is a simpler solution for this. 

I'll appreciate any suggestions.

Javed

RockfordLhotka replied on Wednesday, June 10, 2015

How do you create the FilteredList collection?

Jav replied on Wednesday, June 10, 2015

The main list is created as:

public partial class PxAttributeValueList : MobileList<PxAttributeValue>

Within this class I have a method:

public PxAttributeValueList GetFilteredList(string region, string part)
     {
             PxAttributeValueList Lst = new PxAttributeValueList();
             for (int j = 0; j < this.Count; j++)
                    {
                      // based on region and part
                      Lst.Add(this[j]);
                    } 
            return Lst;
     }

The resulting "FilteredList" is used in Path = FilteredList

Javed

RockfordLhotka replied on Wednesday, June 10, 2015

You are using a very basic list type - MobileList inherits from List<T>. No explicit data binding support, but then binding to a combobox doesn't require anything special.

It is quite puzzling that the same list type works as .Model but not as .Model.FilteredList.

I see no async behavior there, so that probably isn't an issue.

Does your FilteredList property raise PropertyChanged after it has been set/changed?

Jav replied on Wednesday, June 10, 2015

FilteredList after being created as I displayed above simply goes back. In SL it works just fine.  In WPF, I changed the list to

public partial class PxAttributeSelectionList : BusinessListBase<PxAttributeValueList, PxAttributeValue>

But that made no difference to the behavior.  I then created another class and I use it as follows: 

    [Serializable]
    public class PxAttributeSelectionList : BusinessListBase<PxAttributeValueList, PxAttributeValue>
    {
        public static void NewPxAttributeSelectionList(EventHandler<DataPortalResult<PxAttributeSelectionList>> callback)
        {
            var dp = new DataPortal<PxAttributeSelectionList>();
            dp.FetchCompleted += callback;
            dp.BeginFetch();
        }

        public static PxAttributeSelectionList NewPxAttributeSelectionList()
        {
            return new PxAttributeSelectionList();
        }

    }

Then instead of the "FilteredList" I do the following:

public PxAttributeValueList GetFilteredList(string region, string part)
  {
            PxAttributeSelectionList Lst = new PxAttributeSelectionList ();
            for (int j = 0; j < this.Count; j++)
                {
                // based on region and part
                   Lst.Add(this[j]);
                }
             return Lst;
  }

With that list, I can use Path = Model, and everything works just fine.

Javed

Jav replied on Friday, June 12, 2015

Found the culprit.  One of my methods in the chain was getting called mare than once, when it was meant to be called only once. On the last go around it was clearing my list.

Javed

Copyright (c) Marimer LLC