Windows Phone 7 上的列表框上的捏合缩放
我正在尝试向数据绑定列表框添加捏合缩放功能。做到这一点最有效的方法是什么?我已将列表框放置在网格控件内并使其可滚动。
这是我当前的代码。
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="10,0,10,10" Background="Black" >
<ListBox Name="lstText" FontSize="24" Foreground="White" SelectionMode="Single" Margin="10,0,10,10" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel >
<TextBlock Text="{Binding Text}" TextWrapping="Wrap"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
Tap="GestureListener_Tap"
PinchCompleted="GestureListener_PinchCompleted"
Flick="GestureListener_Flick">
</toolkit:GestureListener>
</toolkit:GestureService.GestureListener>
I am trying to add pinch to zoom feature to a data bound ListBox. What is the most efficient way to do this? I have placed the ListBox inside a Grid control and made it scrollable.
This is my current code.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="10,0,10,10" Background="Black" >
<ListBox Name="lstText" FontSize="24" Foreground="White" SelectionMode="Single" Margin="10,0,10,10" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel >
<TextBlock Text="{Binding Text}" TextWrapping="Wrap"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
Tap="GestureListener_Tap"
PinchCompleted="GestureListener_PinchCompleted"
Flick="GestureListener_Flick">
</toolkit:GestureListener>
</toolkit:GestureService.GestureListener>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
列表框不设计为缩放(通过捏合或任何其他方法)。
如果您想实现这一点,您必须以不同的缩放级别重新绘制内容。
不过,您需要克服许多问题:
总结:这几乎肯定是不必要的,而且会非常复杂并且很难做好。如果你真的想尝试一下,然后发布任何问题的代码。
The Listbox isn't designed to be zoomed (via pinching or any other method).
If you want to implement this you must redraw the content at the different zoom levels.
You'd have a number of issues to overcome though:
Summary: This is almost certainly unnecessary and will be very complicated and difficult to do well. If you really want to try this have a go and then post code with any problems.
Alex Yakhnin 提供了滚动长文本的解决方案。
为 WP7 创建可滚动 TextBlock 。 - Alex Yakhnin 的博客
您可以将 TextBlock 包装在 ScrollViewer 中,这可能足以满足您的需求。如果你的文字足够长,随着文字变大,你会遇到各种各样的困难。 Alex 的解决方案是一个控件,它将 StackPanel 包装在 ScrollViewer 中,并将 TextBlock 添加到 StackPanel 的可管理部分中。
Alex Yakhnin offers a solution for scrolling long text.
Creating Scrollable TextBlock for WP7. - Alex Yakhnin's Blog
You can wrap a TextBlock in a ScrollViewer which may be sufficient for your needs. If your text is long enough you will hit a variety of walls as the text gets larger in size. Alex's solution is a control which wraps a StackPanel in a ScrollViewer and adds TextBlocks to the StackPanel in manageable sections.
我自己用manipulationDelta完成了这一点,但它一点也不顺利
在类属性中
在XAML中:
在后面的代码中:
您的CustomSettings类
I've done this myself with manipulationDelta but it's not smooth at all
In the class attributes
In the XAML:
in the code behind:
Your CustomSettings class