Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9043913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:51:08+00:00 2026-06-16T10:51:08+00:00

I have a Windows 8 store app based off of the grouped template project,

  • 0

I have a Windows 8 store app based off of the grouped template project, with some renames etc. However, I’m having a hard time getting the ItemsSource databinding to work for both non-snapped and snapped visual states.

I have a property, that, when set, changes the ItemsSource property, but I can only get one of the controls to bind at a time (either the GridView for non-snapped, or the ListView for snapped).

When I use the following, only the non-snapped binding works and the snapped binding shows no items:

protected PickLeafModel ListViewModel
{
  get
  {
    return (PickLeafModel)m_itemGridView.ItemsSource;
  }

  set
  {
    m_itemGridView.ItemsSource = value;
    m_snappedListView.ItemsSource = value;
  }
}

If I comment out one of the setters, the snapped view shows items but the non-snapped view shows nothing:

protected PickLeafModel ListViewModel
{
  get
  {
    return (PickLeafModel)m_itemGridView.ItemsSource;
  }

  set
  {
    //m_itemGridView.ItemsSource = value;
    m_snappedListView.ItemsSource = value;
  }
}

It’s as if I can bind my view model only to one property at a time. What am I doing wrong?

Since I am generating my data model on another thread (yes, using the thread pool), I cannot make it inherit from DependencyObject. If I do, I get a WrongThreadException.

So to make it work I have done the following:

public class PickLeafModel : IEnumerable
{
  public PickLeafModel()
  {
  }

  public IEnumerator GetEnumerator()
  {
    if (m_enumerator == null)
    {
      m_enumerator = new PickLeafModelViewDataEnumerator(m_data, m_parentLeaf);
    }

    return m_enumerator;
  }

  private SerializableLinkedList<PickLeaf> m_data = 
    new SerializableLinkedList<PickLeaf>();
}

and then my items look like this:

  // Augments pick leafs by returning them wrapped with PickLeafViewData.
  class PickLeafModelViewDataEnumerator : IEnumerator
  {
    public PickLeafModelViewDataEnumerator(
      SerializableLinkedList<PickLeaf> data, PickLeaf parentLeaf)
    {
      m_viewDataList =
        new System.Collections.Generic.LinkedList<PickLeafViewData>();

      foreach (PickLeaf leaf in data)
      {
        PickLeafViewData viewData = new PickLeafViewData();
        viewData.copyFromPickLeaf(leaf, parentLeaf);
        m_viewDataList.AddLast(viewData);
      }

      m_enumerator = m_viewDataList.GetEnumerator();
    }

    public void Dispose()
    {
      m_viewDataList = null;
      m_enumerator = null;
    }

    public object Current
    {
      get
      {
        return m_enumerator.Current;
      }
    }

    public bool MoveNext()
    {
      return m_enumerator.MoveNext();
    }

    public void Reset()
    {
      m_enumerator.Reset();
    }

    private IEnumerator<PickLeafViewData> m_enumerator = null;

    private System.Collections.Generic.LinkedList<PickLeafViewData>
      m_viewDataList;
  }
}

Is there something I’m doing fundamentally wrong?

Help appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:51:09+00:00Added an answer on June 16, 2026 at 10:51 am

    Thanks to Ross for pointing me in the right direction.

    I’m not 100% happy with this solution, but it does work. Basically the idea is that after I get back the PickLeafModel from the worker threads, I transplant its internal data into a derived version of the class which is data binding aware.

    public class PickLeafViewModel : PickLeafModel, IEnumerable
    {
      public PickLeafViewModel()
      {
      }
    
      public PickLeafViewModel(PickLeafModel model)
      {
        SetData(model);
      }
    
      public void SetData(PickLeafModel model)
      {
        model.swap(this);
      }
    
      public IEnumerator GetEnumerator()
      {
        if (m_observableData == null)
        {
          m_observableData = new ObservableCollection<PickLeafViewData>();
    
          var data = getData();
          PickLeaf parentLeaf = getParentLeaf();
          foreach (PickLeaf leaf in data)
          {
            PickLeafViewData viewData = new PickLeafViewData();
            viewData.copyFromPickLeaf(leaf, parentLeaf);
            m_observableData.Add(viewData);
          }
        }
    
        return m_observableData.GetEnumerator();
      }
    

    and the page code is as follows:

    protected PickLeafViewModel ListViewModel
    {
      get
      {
        return DataContext as PickLeafViewModel;
      }
    
      set
      {
        DataContext = value;
      }
    }
    

    whenever I want to set ListViewModel, I can do this:

      ListViewModel = new PickLeafViewModel(model); 
    

    and swap looks like:

    private static void swap<T>(ref T lhs, ref T rhs)
    {
      T temp;
      temp = lhs;
      lhs = rhs;
      rhs = temp;
    }
    
    // Swaps internals with the other model.
    public void swap(PickLeafModel other)
    {
      swap(ref m_data, ref other.m_data);
      ...
    

    Also, PickLeafModelViewDataEnumerator can be deleted altogether.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are working on a C# Xaml-based Windows Store app. We have integrated bing
I am currently working on a Windows 8 app which needs to store some
I have create a Windows Store app which successfully updates its tile (live tile).
I have created a Windows 8 Store App using C# / XAML. My interface
I'm building a Windows Store App and I have a TextBox binded (two-way mode)
I have a windows store app and reviewer indicated that app not working (crashing).
I have developed windows 8 store app with XAML and c# so can I
I have a Windows.Forms based .NET desktop application that stores privileged information in a
I am developing a windows app in c#. I have used three decimal variables:
I have a rails 3.1 app and I am adding carrierwave to store images.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.