[英]Trying to animate lines of a grid onto the screen in a WPF app and detect how many can fit on the screen at a time
I am creating a food menu that displays on a TV screen in a restaurant. 我正在创建一个食物菜单,显示在餐厅的电视屏幕上。 There will be no interaction of the menu itmes, so I need to automatically display the items and rotate through them when all the items do not fit on the screen at one time. 菜单主题没有交互,所以我需要自动显示项目,并在所有项目一次不适合屏幕时旋转它们。
I have all of the components of the project built, even the administration of what the menu items are and which day to display them. 我已经构建了项目的所有组件,甚至管理了菜单项以及显示它们的日期。 Now, I need to finish the display of the items for the TV screen(s). 现在,我需要完成电视屏幕项目的显示。
I am new to WPF, so I'm trying to figure out the best way to do this: 我是WPF的新手,所以我想找出最好的方法:
Any great ideas you guys have that can point me in the right direction will be greatly appreciated! 你们有任何伟大的想法可以指出我正确的方向将非常感谢!
Update: Here's a very rough mockup of what I'm talking about: 更新:这是我正在谈论的一个非常粗略的模型:
You can probably get away with using a Grid or StackPanel and animate the margin value of your elements (use negative margins to slide items in). 您可以放弃使用Grid或StackPanel并为元素的边距值设置动画(使用负边距来滑动项目)。 You need to ensure that the parent element has ClipToBounds set to false so that items can be drawn outside of its bounds. 您需要确保父元素将ClipToBounds设置为false,以便可以在其边界之外绘制项。
To measure an element's height, just use the Measure method on the row element to figure out how much space it needs vertically. 要测量元素的高度,只需使用行元素上的Measure方法来确定它需要垂直的空间大小。 Based on that, you can determine how many elements you can fit in one page. 基于此,您可以确定一页中可以容纳的元素数量。
There's too much work to build everything, however the following should lead you to your goal : 构建所有内容的工作量太大,但以下内容应该会引导您实现目标:
Inherit from Listview add create a 'PartialListView' , with added dependencies properties StartIndex and ItemHeight. 从Listview继承添加创建'PartialListView',添加依赖项属性StartIndex和ItemHeight。 It should build a listview of the right height showing items from StartIndex to StartIndex+ItemHeight. 它应该构建一个正确高度的列表视图,显示从StartIndex到StartIndex + ItemHeight的项目。 (scroller not shown. Use FindDescendant (of type scrollviewer) to find the scrollViewer after listView is loaded, and set its VerticalOffset) (滚动条未显示。使用FindDescendant(类型为scrollviewer)在listView加载后查找scrollViewer,并设置其VerticalOffset)
Create a UserControl with two dependency properties : 使用两个依赖项属性创建UserControl:
1) bind to an ObservableCollection of MenuItems (Item, Calories, ...) 1)绑定到MenuItems的ObservableCollection(Item,Calories,...)
2) an ItemHeight (integer property). 2)ItemHeight(整数属性)。
Then on each collection change you modify IndexList, an Observable collection of numbers {1, 6, 11 }, which are the first indexes of each menu. 然后在每个集合更改时修改IndexList,一个Observable数字集合{1,6,11},它们是每个菜单的第一个索引。
The control code will look like : 控制代码如下所示:
<ListBox ItemsSource="{Binding IndexList, ElementName = mycontrolname}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<ScrollViewer x:Name="PageScroller" ... set to horizontal only, not
showing any bar >
<StackPanel Orientation="Horizontal" />
</ScrollViewer>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<app:PartialListView StartIndex="{Binding }"
IndexCount = "{Binding IndexCount, ElementName = mycontrolname}"
ItemsSource = "{Binding MenuItems , ElementName = mycontrolname}"
/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
switching 'screen' will be done by changing the HorizontalOffset of the PageScroller ScrollViewer. 切换'屏幕'将通过更改PageScroller ScrollViewer的HorizontalOffset来完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.