Winrt listview通过代码滚动到任何项目? [英] Winrt listview scroll to any item via code?

查看:84
本文介绍了Winrt listview通过代码滚动到任何项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个科目。每个科目有500个问题。一旦程序加载设置,它将为您提供选择主题的选项。一旦用户选择了主题,它将加载问题列表。如果问题解决了,那么它显示为绿色。



我想自动滚动到未解决的问题。



ListView in xaml



 <   ListView     x:名称  =  LstQuestions    SelectionMode   =    网格。行  =  1    d:IsLocked   =  True >  
< ListView.ItemsPanel >
< ItemsPanelTemplate >
< WrapGrid 方向 = 水平 / >
< / ItemsPanelTemplate >
< / ListView.ItemsPanel >
< / ListView >





ListView项目是从代码加载的。



 InitializeComponent(); 

for int i = 1 ; i< = 500 ; i ++)
{
Button btn = 按钮();
btn.Width = 120 ;
btn.Height = 120 ;
btn.Click + = Btn_Click;
btn.Content = i;
LstQuestions.Items.Add(btn);
}

LstQuestions.UpdateLayout();

LstQuestions.ScrollIntoView((Button)LstQuestions.Items [_CurrentQuestionNumber]);





我如何实现它。?



我尝试了什么:



我搜索了Google发现了许多方法,但没有一种方法可行。还下载了WinrtXamlToolkit。它提供了扩展的滚动方法。这也行不通。尝试了semanticzoomlocation。到目前为止没有结果。

解决方案

我不知道问题是什么。但是我发现如果你从一个事件中调用ScrollIntoView它会起作用。



所以我创建了Layout_Updated事件。从该事件中调用ScrollIntoView。



 <   ListView     x:名称  =  LstQuestions    SelectionMode   =     Grid.Row   =  1 < span class =code-attribute>   LayoutUpdated   =  LstQuestions_LayoutUpdated    d:IsLocked   =  True >  
< ListView.ItemsPanel >
< ItemsPanelTemplate < span class =code-keyword>>
< WrapGrid 方向 = 水平 / >
< / ItemsPanelTemplate >
< / ListView.ItemsPanel >
< / ListView >







  public 问题()
{
InitializeComponent( );
for int i = 1 ; i< = 500 ; i ++)
{
Button btn = new Button();
btn.Width = 120 ;
btn.Height = 120 ;
btn.Click + = Btn_Click;
btn.Content = i;
LstQuestions.Items.Add(btn);
}
LstQuestions.UpdateLayout();
}







  private   void  LstQuestions_LayoutUpdated( object  sender,对象 e)
{
LstQuestions.ScrollIntoView(LstQuestions.Items [_CurrentQuestionNumber]);
}









现在可行。


I have 4 subjects. Each subject has 500 questions. Once program loads settings it will give you an option to choose subject. Once user selects a subject it will load the list of questions. If question is solved then it is shown as green.

I am trying to scroll to unsolved questions automatically.

ListView in xaml

<ListView x:Name="LstQuestions" SelectionMode="None" Grid.Row="1" d:IsLocked="True">
    <ListView.ItemsPanel>
         <ItemsPanelTemplate>
             <WrapGrid Orientation="Horizontal"/>
         </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>



ListView items are loaded from code.

InitializeComponent();

for(int i=1;i<= 500; i++)
{
     Button btn = new Button();
     btn.Width = 120;
     btn.Height = 120;
     btn.Click += Btn_Click;
     btn.Content = i;
     LstQuestions.Items.Add(btn);
}

LstQuestions.UpdateLayout();

LstQuestions.ScrollIntoView((Button)LstQuestions.Items[_CurrentQuestionNumber]);



How can I achieve it.?

What I have tried:

I searched in Google and found many methods but none of them worked. Also downloaded WinrtXamlToolkit. It provides extended methods for scrolling. This also didn't work. Tried semanticzoomlocation too. So far no results.

解决方案

I don't know what the problem was. But I found out that if you call ScrollIntoView from an event it will work.

So I created Layout_Updated event. Called the ScrollIntoView from that event.

<ListView x:Name="LstQuestions" SelectionMode="None" Grid.Row="1" LayoutUpdated="LstQuestions_LayoutUpdated" d:IsLocked="True">
    <ListView.ItemsPanel>
         <ItemsPanelTemplate>
             <WrapGrid Orientation="Horizontal"/>
         </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>




public Questions()
{  
    InitializeComponent();
    for(int i=1;i<= 500; i++)
    {
         Button btn = new Button();
         btn.Width = 120;
         btn.Height = 120;
         btn.Click += Btn_Click;
         btn.Content = i;
         LstQuestions.Items.Add(btn);
    }
    LstQuestions.UpdateLayout();
}




private void LstQuestions_LayoutUpdated(object sender, object e)
{
   LstQuestions.ScrollIntoView(LstQuestions.Items[_CurrentQuestionNumber]);
}





Now it works.


这篇关于Winrt listview通过代码滚动到任何项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆