English 中文(简体)
某些类型的格里德人
原标题:ListBox layout with some kind of Grid

我有来自XML的数据:

var searched = from c in xml.Descendants("tbody").Descendants("tr")
         let team = c.Element("td").ElementsAfterSelf("td")
         select new Time
            {
                a = c.Element("td").ElementsAfterSelf("td").First().Value,
                b = Int32.Parse(c.Descendants("td").ElementAt(3).Value),
                c = Int32.Parse(c.Descendants("td").ElementAt(4).Value),
                d = Int32.Parse(c.Descendants("td").ElementAt(5).Value),
                e = Int32.Parse(c.Descendants("td").ElementAt(6).Value),
                f = Int32.Parse(c.Descendants("td").ElementAt(7).Value),
                g = Int32.Parse(c.Descendants("td").ElementAt(8).Value),
                h = Int32.Parse(c.Descendants("td").ElementAt(9).Value),
                i = Int32.Parse(c.Descendants("td").ElementAt(10).Value),
                j = float.Parse(c.Descendants("td").ElementAt(11).Value)
            };

Done this, I m showing them in a ListBox:

foreach (var item in searched)
    {
         listBox1.Items.Add(item.a + "  " + item.b + "  " + item.c + "  " + 
           item.d + "  " + item.e + "  " + item.f  + "  " + item.g + "  " + 
           item.h + "  " + item.i + "  " + item.j);
         listBox1.Items.Add("  ");
    }

It prints fine, that s how I wanted it. Now I need to format it. Now, it is printing like this:

a     b    c    d  e  f  g  h  j


However, the variable s content differs in size. So the information do not get very organized. So I wanted something like:

a|b|c|d|e|f|g|h|j
a|b|c|d|e|f|g|h|j

In which the | represents a column. I was thinking about a grid inside a list box but then I got lost on how to do it.

最佳回答

那么,与<代码>ItemTemplate相适应的名录Box是什么?

这是<代码>ListBox:

<ListBox HorizontalAlignment="Left" Margin="12,6,0,0" Name="listBox1" VerticalAlignment="Top">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="150" />
                    <ColumnDefinition Width="150" />
                    <ColumnDefinition Width="150" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding a}" Margin="0,0,12,0" />
                <TextBlock Grid.Column="1" Text="{Binding b}" Margin="0,0,12,0" />
                <TextBlock Grid.Column="2" Text="{Binding c}" Margin="0,0,12,0" />
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

它使用每个项目的网格,将数值分成单独的栏目。 您可以试验一栏大小。

这表明:

private void button1_Click(object sender, RoutedEventArgs e)
{
    List<MyObject> list = new List<MyObject>();
    list.Add(new MyObject() { a = 1, b = 2, c = 3 });
    list.Add(new MyObject() { a = 4, b = 57346, c = 6 });
    list.Add(new MyObject() { a = 7, b = 8, c = 9 });

    listBox1.ItemsSource = list;
}

我只是编制了一份清单,其中附有编造数据,并把它作为名单箱的<编码>。 如果是的话,数据将来自XML。

我使用了这一舱级测试:

public class MyObject
{
    public int a { get; set; }
    public int b { get; set; }
    public int c { get; set; }
}

它只有3个领域来证明它是如何运作的。 你也可以轻易地补充其他领域。 每个新增领域增加一个<代码>ColumnDefinition和TextBlock,载于XAML,并相应设置了<编码>。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签