使用Windows Phone 7的Silverlight创建表

编程入门 行业动态 更新时间:2024-10-26 16:26:35
本文介绍了使用Windows Phone 7的Silverlight创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在WP7上创建一个表格。这是我当前使用的方法,使用带有网格的ListBox作为数据模板。

I'd like to create a table on WP7. This is my current approach using a ListBox with a Grid as the data template.

<ListBox x:Name="ResultsList" Margin="12,0" Grid.Row="1"> <ListBox.Resources> <DataTemplate x:Key="ResultsListItem"> <Grid d:DesignWidth="385" Height="28"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="88"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock x:Name="textBlock1" Margin="0,0,24,0"/> <TextBlock x:Name="textBlock2" Margin="0,0,24,0" VerticalAlignment="Top" Grid.Column="1"/> <TextBlock x:Name="textBlock3" Margin="0,0,24,0" VerticalAlignment="Top" Grid.Column="3"/> </Grid> </DataTemplate> </ListBox.Resources> <ListBox.ItemTemplate> <StaticResource ResourceKey="ResultsListItem"/> </ListBox.ItemTemplate> </ListBox>

问题是,结果表的列大小不相等。网格的列定义适用于每一行,而与其他行无关。这意味着,如果textBlock1中有长文本,则列0将更大。在下一行中,textBlock1中的文本可能更短,导致第0列也比上一行中的第0列短。

The problem is, that the resulting table's columns are not sized equally. The Grid's column definitions are applied to each row independently of the other rows. That means, if there is a long text in textBlock1, column 0 will be larger. In the next row there could be a shorter text in textBlock1, resulting in column 0 also being shorter than the column 0 in the previous row.

所有列如何行大小是否相等?我不想使用固定宽度,因为当方向从纵向更改为横向时,列会自动调整大小。

How can the columns in all rows be sized equally? I don't want to use fixed width because when the orientation changes from portrait to landscape the colums would resize automatically.

有HeaderedItemsControl,但据我所知不适用于Windows Phone 7?

There is the HeaderedItemsControl, but as I understand it it is not available for Windows Phone 7?

推荐答案

这是一个棘手的问题!在WPF中,存在SharedSizeGroup的概念,该概念允许您在多个网格之间共享列宽,但这在Silverlight中不可用。

This is a tricky problem! In WPF there exists the concept of a SharedSizeGroup, which allows you to share column widths across multiple grids, but this is not available in silverlight.

有一些解决方法网络上:

There are a few workarounds on the web:

www.scottlogic.co.uk/blog/colin/2010/11/using-a-grid-as-the-panel- for-an-itemscontrol /

databaseconsultinggroup/blog/2009/05/simulating_sharedsizegroup_in.html

虽然都不是简单的解决方案。

Although neither are simple solutions.

您还可以尝试使用Mike的AutoGrid:

You might also try Mike's AutoGrid:

whydoidoit/2010/10/06/automatic-grid-layout-for-silverlight/

更多推荐

使用Windows Phone 7的Silverlight创建表

本文发布于:2023-11-06 17:31:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564335.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Windows   Phone   Silverlight

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!