How to obtain Multi-level hierarchy with CollectionViewSource to bind to Semantic Zoom in Windows 8.1

非 Y 不嫁゛ 提交于 2019-12-12 03:25:32

问题


I have a Windows 8.1 Application in which I am trying to achieve 3 levels of Hierarchy with CollectionViewSource and then Bind it to my Semantic Zoom

My model class looks as follows

class Transaction
{
    string id {get; set;}
    string name {get; set;}
    DateTimeOffset date {get; set;
}

Sample value of this model could be as follows

[1, Food, 31/08/2014]
[2, Movie, 15/08/2014]
[3, Medicine, 20/07/2014]
[4, GameConsole, 02/07/2014]
[5, MobileBill, 18/06/2014]
[4, Tv, 06/06/2014]

I want to display this data in my Semantic Zoom such that

  1. My ZoomedOutView is a GridView which displays Months like August, July and June.
  2. In my ZoomedInView the data is grouped by the date

To achieve this I have to create these 3 levels in my CollectionViewSource

  1. Month
  2. Date
  3. Individual Transaction

An example data for the above hierarchy is shown below

August (Appears in ZoomedOutView only)
    August 31
        Transaction 1
        Transaction 2
    August 15
        Transaction 3
        Transaction 4
    August 1
        Transaction 5
        Transaction 6

July (Appears in ZoomedOutView only)
    July 20
        Transaction 7
        Transaction 8
    July 2
        Transaction 9
        Transaction 10

June (Appears in ZoomedOutView only)
    June 10
        Transaction 11
        Transaction 12

My Semantic Zoomed Out View will have

August
July
June

My Semantic Zoom ZoomedInView should have

August 31
    Transaction 1
    Transaction 2
August 15
    Transaction 3
    Transaction 4
August 1
    Transaction 5
    Transaction 6
July 20
    Transaction 7
    Transaction 8
July 2
    Transaction 9
    Transaction 10
June 10
    Transaction 11
    Transaction 12

I am trying to group my List into CollectionViewSource as follows

List<Transaction> response = GetTransactions();
var TransactionCollectionViewSource = new CollectionViewSource();
TransactionCollectionViewSource.Source = response.ToGroups(x => x, x => x.date.Month);
TransactionCollectionViewSource.IsSourceGrouped = true;

I have got groupby month, now how do I group this into days again? Should I have 2 CollectionViewSource? Or is it possible to achieve this with just one CollectionViewSource. I am confused.

I would be very glad if someone can point me in the right direction. Thanks in Advance.


回答1:


SemanticZoom: http://msdn.microsoft.com/en-us/library/windows/apps/hh465319.aspx

Try this:

private void Zoom_ViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
{
    if (!e.IsSourceZoomedInView)
    {
        e.DestinationItem.Item = _selectedHubSection;
    }
}

Best of luck!



来源:https://stackoverflow.com/questions/25482570/how-to-obtain-multi-level-hierarchy-with-collectionviewsource-to-bind-to-semanti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!