获取 Grid 中的所有元素并更改其属性
我有一个相当大的 Windows Phone silverlight 网格,大约有 4 x 22 个元素(4 列,22 行),我试图实现一个搜索框,动态更改这些元素的属性及其在网格中的位置。
每个元素都是一个 StackPanel(带有一个图像,后跟一个 TextBlock)。
所以这个页面的 xaml 是这样的:
; <文本框/> <滚动查看器> <网格22x4/>>
我这样做了,这样我就可以滚动该网格,而无需使顶部文本框也滚动。
我现在想要的是在文本框上实现 textchange 事件,以便它过滤这些元素。例如,有 3 个元素的名称以字母“z”开头,所以当我在文本框中输入“z”时,我想要的是名称不以“z”开头的所有元素将其可见性更改为“折叠”并且将所有以“z”开头的移动到第一行和第一列。
但我如何在代码中访问这些元素?如果我有网格对象,什么方法返回元素列表(如果有)以便我可以操作它们?
另外,这是最好的方法吗?在我看来,这对于移动应用程序来说可能有点开销,欢迎任何提示。
谢谢。
i have a windows phone silverlight grid that is quite big, around 4 x 22 elements (4 columns, 22 rows) and im trying to implement a search box that dynamically changes properties of those elements and their position in the grid.
each element is a StackPanel (with an Image followed by a TextBlock).
so this page xaml is something like:
<stackpanel> <textbox /> <scrollviewer> <grid 22x4 /> </scrollviewer> </stackpanel>
ive done it like this so i can scroll that grid without making the top textbox scroll too.
what i want now is to implement the textchange event on the textbox so it filters those elements. for instance there are 3 elements whose name begin with the letter 'z', so what i want when i type 'z' into the textbox is that all elements whose name dont start with 'z' to change their visibility to "collapse" and move all the ones that start with 'z' to the firsts row and columns.
but how can i access those elements in code? if i have the grid object, what method returns the list of elements if there is any so i can manipulate them?
also, is this the best way to do it? the way i see it it might be a bit overhead for a mobile application, any tips are welcome.
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白你想如何过滤以及你的网格元素是什么类型。但我的示例显示了过滤所有网格元素、更改 Grid.Row、Grid.Column、Visibility 属性的方法。
I don't exactly understand how do you want to filter and what kind your grid elements are. But my example shows the way to filter all grid elements, change
Grid.Row
,Grid.Column
,Visibility
properties.