我正在使用Windows Phone 8应用程序,并且我想实现一个按钮,该按钮可以跳转到ListHeader
的顶部LongListSelector
(ListHeader
包含一些用于过滤内容的单选按钮) 。有没有办法做到这一点?有没有办法跳转到LongListSelector的ListHeader?
0
A
回答
0
在您的按钮处理程序中,使用此方法从LongListSelector的模板中获取ViewPortControl
。
public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
{
// Confirm parent and childName are valid.
if (parent == null)
{
return null;
}
T foundChild = null;
int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < childrenCount; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
// If the child is not of the request child type child
var childType = child as T;
if (childType == null)
{
// recursively drill down the tree
foundChild = FindChild<T>(child, childName);
// If the child is found, break so we do not overwrite the found child.
if (foundChild != null)
{
break;
}
}
else if (!string.IsNullOrEmpty(childName))
{
var frameworkElement = child as FrameworkElement;
// If the child's name is set for search
if (frameworkElement != null && frameworkElement.Name == childName)
{
// if the child's name is of the request name
foundChild = (T)child;
break;
}
// Need this in case the element we want is nested
// in another element of the same type
foundChild = FindChild<T>(child, childName);
}
else
{
// child element found.
foundChild = (T)child;
break;
}
}
return foundChild;
}
然后使用THIS滚动到ViewPortControl
的顶部。
用法:
private void Button_OnClick(object sender, RoutedEventArgs e)
{
var viewPort = FindChild<ViewportControl>(yourLongListSelector, "ViewportControl");
viewPort.SetViewportOrigin(new Point(0,0));
}
如果你想知道在哪里的ViewPortControl是从哪里来的,这里的LongListSelector
的风格。
<Style x:Key="LongListSelectorStyle1" TargetType="phone:LongListSelector">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:LongListSelector">
<Grid Background="{TemplateBinding Background}" d:DesignWidth="480" d:DesignHeight="800">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ScrollStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="00:00:00.5"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Scrolling">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="VerticalScrollBar"/>
</Storyboard>
</VisualState>
<VisualState x:Name="NotScrolling"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<ViewportControl x:Name="ViewportControl" HorizontalContentAlignment="Stretch" VerticalAlignment="Top"/>
<ScrollBar x:Name="VerticalScrollBar" Grid.Column="1" Margin="4,0,4,0" Opacity="0" Orientation="Vertical"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
相关问题
- 1. 有没有办法在Textmate中从方法跳转到方法?
- 2. 有没有办法跳过pytest夹具?
- 3. 有没有办法用tweepy光标跳转页面?
- 4. 有没有办法跳过从shouldAutorotateToInterfaceOrientation旋转动画?
- 5. 有没有办法在MATLAB中“跳转滚动”?
- 6. 有没有办法跳转到C中的变量定义的行?
- 7. 有没有办法跳转到iPython/Jupyter笔记本中包含错误的行?
- 8. 有没有办法跳转到列表视图中的特定项目
- 9. 链接没有跳转到
- 10. 在C++中,有没有办法从一个函数跳转到另一个
- 11. 没有办法在VSCode中的冲突之间跳转吗?
- 12. 有没有办法在Pymongo 3.0中跳过insert_many的现有_id?
- 13. 将项目相关变量绑定到longlistselector(WP8)中的listheader
- 14. LongListSelector分组,跳转列表
- 15. 有没有办法使sem_wait不旋转?
- 16. 从CodeBehind跳转到锚没有转贴
- 17. 有没有什么办法让Flash动画中的时间线跳转?
- 18. 滚动/跳转到没有jQuery的ID
- 19. 有没有办法跳过Sincerely Ship库中的裁剪屏幕?
- 20. Android - 有没有办法跳过HTC One的“锁屏”?
- 21. 在Python中读取文件时,有没有办法跳到特定的行号?
- 22. 有没有办法跳到代码的特定部分进行调试?
- 23. 有没有办法在Rails 3.1中跳过序列化?
- 24. 颠覆结账:有没有办法跳过一个子树?
- 25. 有没有办法在custom_active管理行动,以跳过认证
- 26. Acts_as_Version有没有办法在保存时跳过版本控制?
- 27. 有没有办法在基类中跳过测试?
- 28. 有没有办法跳过绘制框架?
- 29. Mongoose/NodeJS - 有没有办法跳过中间件?
- 30. 当我推送heroku时,有没有办法跳过预编译?
您是否尝试过使用'LongListSelector.ScrollTo()'滚动到第一项?不知道这是否会将头部撞到视图中,但您可以尝试一下。 – Pantelis
@Pantelis我有。虽然这会滚动到项目列表的顶部,但它不会滚动到足以显示ListHeader。 – Kamaros