yal*_*tta 6 c# listview scrollviewer windows-store-apps windows-8.1
我正在构建一个照片应用程序,使用a FlipView和a listView作为分页.当我点击它中的缩略图时,ListView它显示了我的相同图片FlipView.当我滑入时FlipView,所选的任何照片都会选择相同的照片ListView.这是通过添加到它们两个来完成的:
致ListView:
SelectedIndex="{Binding Path=SelectedIndex, ElementName=flipView1, Mode=TwoWay}
Run Code Online (Sandbox Code Playgroud)
对于FlipView:
SelectedIndex="{Binding Path=SelectedIndex, ElementName=listView1, Mode=TwoWay}
Run Code Online (Sandbox Code Playgroud)
对于ListView SelectionChanged我添加的事件:
if (e.AddedItems.Count > 0)
listView1.ScrollIntoView(e.AddedItems.First(), ScrollIntoViewAlignment.Leading);
Run Code Online (Sandbox Code Playgroud)
我唯一的问题是,当我滑动时FlipView,所选的图片被选中,ListView但是ScrollViewer没有滚动到它.我尝试WinRTXamlToolkit用来改变以下位置ScrollViewer:
private void pageRoot_Loaded()
{
// count number of all items
int itemCount = this.listView1.Items.Count;
if (itemCount == 0)
return;
if (listView1.SelectedIndex >= itemCount)
listView1.SelectedIndex = itemCount - 1;
// calculate x-posision of selected item
double listWidth = this.listView1.ActualWidth;
double xPos = (listWidth / itemCount) * listView1.SelectedIndex;
// scroll
var scrollViewer2 = listView1.GetFirstDescendantOfType<ScrollViewer>();
if (scrollViewer2 != null)
scrollViewer2.ChangeView(xPos, 0.0, 1);
}
Run Code Online (Sandbox Code Playgroud)
第一次listWidth是1600.0,然后它变成了0.0所有的时间,这给了xPos = 0.0!
我怎样才能解决这个问题?
https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.listview.aspx
您应该使用两种“ScrollIntoView”方法之一。
| 归档时间: |
|
| 查看次数: |
1810 次 |
| 最近记录: |