Enabling ScrollViewer HorizontalSnapPoints with bindable collection

后端 未结 2 761
情歌与酒
情歌与酒 2021-02-04 09:13

I\'m trying to create a similar experience as in the ScrollViewerSample from the Windows 8 SDK samples to be able to snap to the items inside a ScrollViewer when scrolling left

2条回答
  •  醉酒成梦
    2021-02-04 09:55

    Getting snap points to work for bound collections can be tricky. For snap points to work immediate child of ScrollViewer should implement IScrollSnapPointsInfo interface. ItemsControl doesn't implement IScrollSnapPointsInfo and consequently you wouldn't see snapping behaviour.

    To work around this issue you got couple options:

    • Create custom class derived from ItemsControl and implement IScrollSnapPointsInfo interface.
    • Create custom style for items control and set HorizontalSnapPointsType property on ScrollViewer inside the style.

    I've implemented former approach and can confirm that it works, but in your case custom style could be a better choice.

提交回复
热议问题