简体   繁体   English

c# WPF GridView 列显示空项目

[英]c# WPF GridView Columns Showing Empty Items

I am trying to make a WPF program that will go through a list of items and put each of those listed items into a list view.我正在尝试制作一个 WPF 程序,该程序将遍历项目列表并将每个列出的项目放入列表视图中。

However when I add the items to the list view the columns just show up empty (but highlight when I mouse over the list view so the items are being added)但是,当我将项目添加到列表视图时,列只显示为空(但当我将鼠标悬停在列表视图上时突出显示,以便添加项目)

I was just wondering why the values are not showing up in the columns.我只是想知道为什么这些值没有显示在列中。 Also if it helps I know that "SetData" has values in it because I did a step-into and watched the values be added.此外,如果它有助于我知道“SetData”中有值,因为我做了一个步骤并观察了添加的值。

XAML XAML

<ScrollViewer Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="4">
        <ListView x:Name="LIV_SetList">
            <ListView.View>
                <GridView>
                    <!--Each column will display a specific property of the set, its name, code and total number of cards-->
                    <GridViewColumn Header="Set Name" DisplayMemberBinding="{Binding SetName}"/>
                    <GridViewColumn Header="Set Code" DisplayMemberBinding="{Binding SetCode}"/>
                    <GridViewColumn Header="Number Of Cards" DisplayMemberBinding="{Binding SetCount}"/>
                </GridView>
            </ListView.View>

        </ListView>
    </ScrollViewer>

.cs 。CS

 // Shove all the data just gathered into a Set Overview, and put that set overview into a list item which is then added to the listview 
                    Classes.SetOverview SetData = new Classes.SetOverview { SetName = SetReader["name"].ToString(), SetCode = TempCode, SetCount = SetSize };
                    LIV_SetList.Items.Add(SetData);

SetOverview Class SetOverview 类

public class SetOverview
    {
        //This Is Used On The Main Window To Display Information Regarding A Given Sets Name Code And Number Of Cards
        public string SetName;
        public string SetCode;
        public int SetCount; 
    }

It's hard to say for sure without know how you define the SetOverview class but if it's just a class with 3 string members (SetName, SetCode, SetCount) make sure they are defined as public properties (with get and set) not just regular strings.在不知道如何定义 SetOverview 类的情况下很难确定,但如果它只是一个具有 3 个字符串成员(SetName、SetCode、SetCount)的类,请确保将它们定义为公共属性(使用 get 和 set)而不仅仅是常规字符串。 for example:例如:

public class SetOverview
{
    public string SetName { get; set; }
    public string SetCode { get; set; }
    public string SetCount { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM