多级标题GridView WPF [英] Multi-level header GridView WPF

查看:80
本文介绍了多级标题GridView WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将listview视图设置为具有这样复杂标题(基于我创建的3维对象列表)的gridview:

I need to set the listview view to a gridview that have a complex header like this (based on a 3 dimensional object list i created):

| ---------- LEVEL 0 ------------  |
| -- Level 1a --  | -- Level 1b -- |  
| Lvl A |  Lvl B  | Lvl A  | Lvl B |

这比我的对象模型少了

public class Measures
{
    public string Caption { get; set; }
    public List<Threshold> ThresholdList { get; set; }
}

public class Threshold
{
    public string Caption { get; set; }

    public double Value1 { get; set; }
    public double Value2 { get; set; }
    public double Value3 { get; set; }
    public double Value4 { get; set; }
}

我必须绑定一个动态列表Measures(这是我的级别0),然后绑定一个动态列表Threshold(级别1a ...),并且对于每个阈值显示值1到4,如果它们是! = 0

i've to bind a dynamic list of Measures (this is my level 0), then a dynamic list of Threshold (level 1a...) and for each threshold display values1 to 4 if they are != 0

推荐答案

这样的事情如何?

<ListBox x:Name="MainListBox">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Label Content="{Binding Path=Caption}" HorizontalAlignment="Center" />

                        <ListBox Grid.Row="1" ItemsSource="{Binding Path=ThresholdList}" >
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                                    </StackPanel>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>

                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>

                                        <Label Content="{Binding Path=Caption}" HorizontalAlignment="Center" />

                                        <StackPanel Grid.Row="1" Orientation="Horizontal">
                                            <Label Content="{Binding Path=Value1}" />
                                            <Label Content="{Binding Path=Value2}" />
                                            <Label Content="{Binding Path=Value3}" />
                                            <Label Content="{Binding Path=Value4}" />
                                        </StackPanel>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>


                        </ListBox>

                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

您可能需要将Value1,Value2属性转换为一个集合,以便动态显示非零值,并使用与我用来显示阈值的相同的ListBox/StackPanel方法.

You might need to convert the Value1, Value2 properties into a collection in order to dynamically display the non-zero ones and use the same ListBox/StackPanel approach that I used to display the thresholds.

这给出了输出:

为了完成该帖子,这是我使用的代码:

And just to complete the post, here is the code I used:

List<Measures> measuresList = new List<Measures>();

Measures measures = new Measures()
{
    Caption = "LEVEL 0",
    ThresholdList = new List<Threshold>()
};

measures.ThresholdList.Add(new Threshold()
{
    Caption = "Level 1a",
    Value1 = 1,
    Value2 = 2,
    Value3 = 3,
    Value4 = 4
});

measures.ThresholdList.Add(new Threshold()
{
    Caption = "Level 1b",
    Value1 = 5,
    Value2 = 6,
    Value3 = 7,
    Value4 = 8
});

measuresList.Add(measures);

this.MainListBox.ItemsSource = measuresList;

这篇关于多级标题GridView WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆