我有一个问题,这让我发疯:
当我第一次进入“停止列表”页面,回到菜单,然后进入“收藏夹”页面并单击并从列表中停止时,则ScrollIntoView无法正常运行所有应用程序。
但是..当我第一次进入Favouritepage,然后点击了一个sto然后ScrollIntoView可以运行所有时间的应用程序。
ListView1
是ListView,我想要滚动,这些项目来自List<test>
;
这是菜单代码,我正在切换页面:
//favourite
private void Button3_Click(object sender, RoutedEventArgs e)
{
if (!loaded)
return;
if(MainWindowStopList.loaded == false)
MainPage.gui.setPage = typeof(Pages.MainWindowStopList); //cache page if not exist, to memory
MainPage.gui.setPage = typeof(Pages.MainWindowFav);
MainPage.gui.setBackButtonVisibility = Visibility.Visible;
}
//stops
private void Button1_Click(object sender, RoutedEventArgs e)
{
if (!loaded) return;
if (MainWindowFav.loaded == null)
MainPage.gui.setPage = typeof(Pages.MainWindowFav); // this same, cache if not exist;
MainPage.gui.setPage = typeof(Pages.MainWindowStopList);
MainPage.gui.setBackButtonVisibility = Visibility.Visible;
}
代码在哪里,我从收藏夹导航到
MainWindowStopList.preparefromfav(HTMLServices.przystankinames.ElementAt(item.id));
MainPage.gui.setPage = typeof(MainWindowStopList);
以下是函数,我在MainWindowStopList
中使用ListView1执行某些操作:
public MainWindowStopList()
{
this.InitializeComponent();
gui = this;
lista2 = new List<test>();
lista3 = new ObservableCollection<test3>();
selectedPrzystanek = new PrzystankiNames();
ListView1.SelectionChanged += (se, fe) =>
{
(se as ListView).ScrollIntoView(tempPrzystankiNames);
//if above not works from stackoverflow
var lv = se as ListView;
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromSeconds(2);
dt.Tick += (o, o1) =>
{
dt.Stop();
lv.ScrollIntoView(tempPrzystankiNames);
};
dt.Start();
};
this.Loaded += (s, f) =>
{
if (!string.IsNullOrEmpty(tempPrzystankiNames.name))
ListView1.SelectedIndex = lista.IndexOf(tempPrzystankiNames);
};
}
public static void preparefromfav(PrzystankiNames pr)
{
if(gui.ListViewSearchable.Visibility == Visibility.Visible)
{
gui.ListViewSearchable.Visibility = Visibility.Collapsed;
gui.ListView1.Visibility = Visibility.Visible;
}
Grid.SetColumnSpan(gui.ListView1, 1);
gui.ResultListView.Visibility = Visibility.Visible;
gui.tempPrzystankiNames = pr;
gui.showListView2(pr); //here i'm doing nothing with listview
}
private void reset(object sender)
{
navigated_from = false;
foreach (ListView gr in MainWindowLinesInfoHours.FindVisualChildren<ListView>(this))
{
if (gr == sender || gr == ListView1 || gr == ListViewSearchable)
continue;
gr.SelectedIndex = -1;
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
reset(new object());
}
那么,为什么这个滚动不起作用?有人有任何想法吗?