即使有C#,ListView也不会显示这些项目

时间:2017-06-22 10:22:32

标签: c# wpf listview

我在XAML中有一个列表视图:

<ListView HorizontalAlignment="Stretch" x:Name="jobs"  VerticalAlignment="Stretch" DockPanel.Dock="Top" Foreground="Black" SelectionMode="Single" SelectionChanged="selectionJobChanger" IsSynchronizedWithCurrentItem="False">
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Foreground" Value="Black"/>
                            <Setter Property="Background" Value="Yellow"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>
                    <GridView.ColumnHeaderContainerStyle>
                        <Style BasedOn="{StaticResource {x:Type GridViewColumnHeader}}" TargetType="{x:Type GridViewColumnHeader}">
                            <Setter Property="IsHitTestVisible" Value="False"/>
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        </Style>
                    </GridView.ColumnHeaderContainerStyle>
                    <GridViewColumn Header="Commessa" Width="Auto" DisplayMemberBinding="{Binding PrjCode}"/>
                    <GridViewColumn Header="Creazione" Width="Auto" DisplayMemberBinding="{Binding ValidFrom}"/>
                    <GridViewColumn Header="Descrizione" Width="Auto" DisplayMemberBinding="{Binding PrjName}"/>
                    <GridViewColumn Header="Tipo" Width="Auto"  DisplayMemberBinding="{Binding Prototype}"/>
                    <GridViewColumn Header="Project Engineer" Width="Auto" DisplayMemberBinding="{Binding ProjectEngineer}"/>
                    <GridViewColumn Header="Product Manager" Width="Auto" DisplayMemberBinding="{Binding ProductManager}"/>
                </GridView>
            </ListView.View>
        </ListView>

绑定到此模型:

public partial class Job
    {
        public string PrjCode;
        public string PrjName;
        public char Prototype;
        public DateTime ValidFrom;
        public DateTime ValidTo;
        public string ProductManager;
        public string ProjectEngineer;
    }

在视图的codeBehind中,我填充了listview:

 public void showJobsList(List<Job> listOfJobs)
        {
            jobs.Items.Refresh();
            jobs.ItemsSource = listOfJobs;
            jobs.Items.Refresh();
        }

在使用来自查询的数据填充模型后,在演示者的构造函数内调用此方法。

问题是在listView中我没有看到任何项目,但是我确定它们存在,因为我可以看到,在鼠标悬停时,listView中的几个空行以及我可以正确获取其他范围的这些值,但我希望listView正常工作正常。

0 个答案:

没有答案