c# - 绑定(bind)/绑定(bind)两个 LongListSelectors 的滚动位置

标签 c# xaml windows-phone-7 windows-phone-8 windows-phone

在我的 Windows Phone 应用程序中,我有两个 LongListSelectors并排在页面上。我想做到这一点,以便当用户滚动其中一个时,另一个滚动相同的量。

两个 LongListSelectors 具有始终具有相同高度的 ItemTemplates。您可以将其视为模仿 Excel 中的卡住列(左侧的 LongListSelector 仅垂直滚动,右侧的水平和垂直滚动。

任何人都可以为我指明正确的方向吗?如果无法通过绑定(bind)完成,我愿意在代码隐藏或其他任何方式中进行。

最佳答案

您可以通过连接到 LongListSelector 的 ViewportControl 来完成此操作。当一个 LLS 的视口(viewport)改变时,改变另一个 LLS 的视口(viewport)。我猜你只需要两个 LLS,所以一个 DependencyProperty 应该可以解决问题。我写了a blog包含有关如何实现此目标的所有详细信息。

简而言之,就是需要一个 DependencyProperty

public double ScrollPosition
{
    get { return (double)GetValue(ViewPortProperty); }
    set { SetValue(ViewPortProperty, value); }
}

public static readonly DependencyProperty ViewPortProperty = DependencyProperty.Register(
    "ScrollPosition", 
    typeof(double), 
    typeof(MyLongListSelector), 
    new PropertyMetadata(0d, OnViewPortChanged));

并在视口(viewport)改变时设置属性。

private void OnViewportChanged(object sender, ViewportChangedEventArgs args)
{
    ScrollPosition = _viewport.Viewport.Top;
}

然后将属性绑定(bind)到您的 xaml 中的每个 LLS

<dataBoundApp1:MyLongListSelector x:Name="MainLongListSelector" ItemsSource="{Binding Items}"
                                    ScrollPosition="{Binding ScrollPosition, ElementName=MainLongListSelector2, Mode=TwoWay}"/>
<dataBoundApp1:MyLongListSelector x:Name="MainLongListSelector2" ItemsSource="{Binding Items}" Grid.Column="1" 
                                    ScrollPosition="{Binding ScrollPosition, ElementName=MainLongListSelector, Mode=TwoWay}"/>

关于c# - 绑定(bind)/绑定(bind)两个 LongListSelectors 的滚动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20999565/

相关文章:

c# - JSON 嵌套数组

c# - WP7 WLAN检测(我是怎么上网的)

windows-phone-7 - 如何在 WP7 和 Azure 项目之间共享模型

asp.net-mvc - 我应该如何使用OpenID从Windows Phone 7应用程序对WCF数据服务进行身份验证?

c# - 与方法类型的接口(interface)取决于实现类

c# - 在 Windows 10 移动版上启动画面矩形坐标返回屏幕尺寸

c# - 以编程方式检查 .NET Framework 版本 - 我应该这样做吗?

xaml - Winrt 中的网格效果

c# - 我们可以知道窗口是否已被用户或 WPF 上的代码关闭吗?

c# - 许多条目带有 OnItemsChanged(),如何删除旧条目