LongListSelector and DataTemplateSelector

前端 未结 3 1191
无人共我
无人共我 2021-02-15 14:53

I\'m using the LongListSelector to realize List or Grid display for my items. For this, I created a DataTemplateSelector and I change the LayoutMode property at runtime. This is

3条回答
  •  天命终不由人
    2021-02-15 14:55

    I've done something similar with my app, but allowed the user to choose the LayoutMode of LLS using an Appbar button. I basically change the LongListSelector.LayoutMode and then it's ItemTemplate in code and the LLS automatically refreshes itself. I'm not sure if this will help, but here's my code.

    private void layoutModeButton_Click(object sender, EventArgs e)
        {
            ApplicationBarIconButton layoutModeButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
    
            if (MainLongListSelector.LayoutMode == LongListSelectorLayoutMode.Grid)
            {
                MainLongListSelector.LayoutMode = LongListSelectorLayoutMode.List;
                MainLongListSelector.ItemTemplate = this.Resources["ListListLayout"] as DataTemplate;
                layoutModeButton.IconUri = _gridButtonUri;
                layoutModeButton.Text = "grid";
            }
            else
            {
                MainLongListSelector.LayoutMode = LongListSelectorLayoutMode.Grid;
                MainLongListSelector.ItemTemplate = this.Resources["GridListLayout"] as DataTemplate;
                layoutModeButton.IconUri = _listButtonUri;
                layoutModeButton.Text = "list";
            }
        }
    

    You might have figured out the answer already, but just to add to the conversation: this gives me really good performance for a fairly large amount of data. Maybe you can do something similar when navigating back to the page after changing the layout in settings?

提交回复
热议问题