LongListSelector and DataTemplateSelector

前端 未结 3 1136
无人共我
无人共我 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 15:21

    Here is one walk around. (Maybe the problem will be corrected with WP 8.1 Update, along with others I've spotted working with LLS. I know - this idea is ugly, hard and so on, but maybe it will be enough for your purpose:

    Becouse the problem concerns 'reloading' LLS, I've forced it to initialize it every time I navigate to the page (in fact I need to initialize the whole Page - it won't work only with LLS). I've moved InitializeComponent() and buttons events and so on to OnNavigatedTo():

     protected override void OnNavigatedTo(NavigationEventArgs e)
      {
         base.OnNavigatedTo(e);
    
         this._contentLoaded = false;
         InitializeComponent();
    
         first.Click += first_Click;
         second.Click += second_Click;
         ItemLongListSelector.ItemsSource = Items;
      }
    

    At least OnContentChanged() is fired that many Times its needed. Code you can find here.

提交回复
热议问题