多级标题 GridView WPF

发布于 2024-10-14 21:27:36 字数 719 浏览 2 评论 0原文

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

| ---------- 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 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 |

EDIT: This is more ore less my object model

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; }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不交电费瞎发啥光 2024-10-21 21:27:36

像这样的事情怎么样:

<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 方法。

这给出了输出:

Screenshot

为了完成这篇文章,这里是我使用的代码:

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;

How about something like this:

<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>

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.

This gives the output:

Screenshot

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;
幽蝶幻影 2024-10-21 21:27:36

Level 0 是ListView吗?级别 1A 和级别 1b 是您想要在级别 0 列表视图内的两个不同模板化列中的 Gridview?那么级别 A 和级别 b 是级别 1a 和级别 1b 中另外 2 个模板化列内的另外两个网格视图吗?

您也许能够将此嵌套 GridView 使用的相同概念转换为 WPF

http://forums.asp。 net/t/1071521.aspx

我自己没有在 wpf 中尝试过,但 gridviews 似乎是类似构建的。
只需使用面板而不是 Div,就可以减少因担心客户端/服务器端调用而带来的头痛。

此外,数据集比列表工作得更好。

这是一些关于我之前如何设置嵌套数据集的伪代码

DataSet ds1 = new DataSet();
        ds1.Tables.Add(m_DataLayer.GetRealA_Data(X, Y).Copy()); Returns Table ["A"]
        ds1.Tables.Add(m_DataLayer.GetB_Empty().Copy());// Returns Table ["B"]
        ds1.Tables.Add(m_DataLayer.GetC_Empty().Copy());// Returns Table ["C"]
        ds1.Tables.Add(m_DataLayer.GetD_Empty().Copy());// Returns Table ["D"]

        ds1.Relations.Add("b", ds1.Tables["A"].Columns["A_id"], ds1.Tables["B"].Columns["A_id"]);
        ds1.Relations.Add("c", ds1.Tables["B"].Columns["B_id"]
            , ds1.Tables["C"].Columns["B_id"]);
        ds1.Relations.Add("d", ds1.Tables["C"].Columns["C_id"]
            , ds1.Tables["D"].Columns["D_id"]);

        dt_TheGridViewDataSet = ds1;
        TheGridView.DataSource = ds1;

Level 0 Is a ListView? Level 1A and level 1b are Gridviews that you want inside two different templated columns inside the level 0 List view? Then level A and level b are two more grid views inside 2 more templated columns in level 1a and level 1b?

You might be able to convert the same concept this nested GridView uses into WPF

http://forums.asp.net/t/1071521.aspx

I haven't tried it myself in wpf, but gridviews appeared to be built similarly.
Just use panels instead of Divs, and less head aches with having to wory about client/serverside calls.

Also Datasets work nicer then lists.

Here is some psuedo code on how I've set up Nested Datasets before

DataSet ds1 = new DataSet();
        ds1.Tables.Add(m_DataLayer.GetRealA_Data(X, Y).Copy()); Returns Table ["A"]
        ds1.Tables.Add(m_DataLayer.GetB_Empty().Copy());// Returns Table ["B"]
        ds1.Tables.Add(m_DataLayer.GetC_Empty().Copy());// Returns Table ["C"]
        ds1.Tables.Add(m_DataLayer.GetD_Empty().Copy());// Returns Table ["D"]

        ds1.Relations.Add("b", ds1.Tables["A"].Columns["A_id"], ds1.Tables["B"].Columns["A_id"]);
        ds1.Relations.Add("c", ds1.Tables["B"].Columns["B_id"]
            , ds1.Tables["C"].Columns["B_id"]);
        ds1.Relations.Add("d", ds1.Tables["C"].Columns["C_id"]
            , ds1.Tables["D"].Columns["D_id"]);

        dt_TheGridViewDataSet = ds1;
        TheGridView.DataSource = ds1;
对不⑦ 2024-10-21 21:27:36

你有没有想过它应该如何表现——你的标题?

制作一个看起来像您建议的那样的标题很容易 - 您可以通过编程方式使用一些网格构建它 - 但这只是标题。您是否还应该能够像通常使用列表视图标题一样调整它的大小?

也许您正在寻找类似 TreeListView 的东西?

http://www.codeproject.com/KB/WPF/TreeListView.aspx

我认为这就是我所追求的显示多维数据的方式——它很容易理解和使用,而自定义列表视图很难实现正确的行为。

Have you thought about how it should behave - your header that is?

It is easy enough to make a header that looks like the one you suggest - you could build it with some grids programatically - but that is just the header. Should you also be able to resize it like you normally can with a listview header?

Maybe you looking for something like a TreeListView?

http://www.codeproject.com/KB/WPF/TreeListView.aspx

I think that is what I would go after to display multidimentional data - it is easy to understand and use, where a custom listview can be hard to implement to behave right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文