locked
ItemsControl with Another ItemsControl inside it RRS feed

  • Question

  • I have the following Classes:

        public class agentes
        {
            [PrimaryKey]
            public string id { get; set; }
            public string idContinente { get; set; }
            public string idCountry { get; set; }
            public string title { get; set; }
            public string desc { get; set; }
        }
    and
        public class country
        {
            [PrimaryKey]
            public string id { get; set; }
            public string idContinent { get; set; }
            public string title { get; set; }
    
        }
    i also have 2 other classes, and have a List of objects of each of those types , country and agents.

    my List<agents> is filled with the results from a Database query to a sqlite database that looks something like this:
    public List<agentes> GetAllAgents()
            {
                List<agentes> AllAgents = new List<agentes>();
                using (var db = new SQLite.SQLiteConnection(app.DBPath))
                {
                    var query = db.Table<agentes>().OrderBy(c => c.idCountry);
                    foreach (var _Agent in query)
                    {
                        var Agente = new agentes()
                        {
                            desc = _Agent.desc,
                            id = _Agent.id,
                            idContinente = _Agent.idContinente,
                            idCountry = _Agent.idCountry,
                            title = _Agent.title,
                        };
                        AllAgents.Add(Agente);
                    }
                }
                return AllAgents;
            }

    Now, what i intend to do , is a list of agents organized by country so it looks something like
    Country Name
    agents
    agents
    agents

    Country Name
    agents
    agents
    agents



    i started with something like this but clearly it inst whats needed

    <ScrollViewer  Margin="30,30,0,30" Height="444">
                    <ItemsControl Name="ListCountries">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding title}" Foreground="Red" />
                                    <ItemsControl Name="AgentsByCountry" >
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding desc}" Foreground="Black" />
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </StackPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>

    anyone got any suggestions how i can do this?

    Friday, February 7, 2014 1:03 PM

Answers

  • Hi,

    You can group data in a  ListView or GridView Control. See How to group items in a list or grid 

    And you can see XAML GridView grouping and SemanticZoom sample .

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    • Edited by Anne Jing Monday, February 10, 2014 3:28 AM edit
    • Marked as answer by Anne Jing Thursday, February 27, 2014 9:08 AM
    Monday, February 10, 2014 3:27 AM