开发者

How to display rows with embedded tables in Windows Phone 7?

开发者 https://www.devze.com 2023-01-09 06:21 出处:网络
I\'m working on an app that has rows in the following format. I\'ve numbered the rows for clarity. The rows alternate background, so even rows are all one color and odd rows are another. I\'ve it work

I'm working on an app that has rows in the following format. I've numbered the rows for clarity. The rows alternate background, so even rows are all one color and odd rows are another. I've it working using a grid containing x number of rows, and within each row i create another grid with two rows and two columns to organize the d开发者_运维问答ata. I'm new to WP7 dev and have a little experience with Silverlight. It seems like there should be an easier way of doing this, but I haven't found a suitable user control. It feels like I'm doing this the hard way, but I haven't found a user control designed for this layout.

--------------------------------
1       label: data
               more data
--------------------------------
2       label: data
               more data
--------------------------------
3       label: data
               more data
--------------------------------


You could do this with a ListBox rather than nested grids.
For example, create a new list project and do the following:

In mainpage.xaml, change line 35 to be the following:

<StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal" Background="{Binding Converter={StaticResource myconverter}}">

Add the following to app.xaml:

<Application.Resources>
    <alternateRows:MyConverter x:Key="myconverter" />
</Application.Resources>

add a new class called MyConverter with the following

public class MyConverter: IValueConverter
{
    bool flag = false;

    SolidColorBrush brush1 = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
    SolidColorBrush brush2 = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        flag = !flag;
        return flag ? brush1 : brush2;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

This should server as a working example that you can adjust as you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消