0

I have in my XAML a listview:

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

that is binded to this model:

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

In the codeBehind of the view I populate the listview:

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

This method is called inside the constructor of the presenter after populating the model with data coming from a query.

The problem is that in the listView I dont's see any item, but I'm sure that they are present because I can see, at mouse hover, several empty lines inside the listView and after I can get correctly these value for other scopes, but I desire that the listView works fine as is normal to be.

NoeDag
  • 1
  • 2
  • Why not using MVVM? You don't have to call `Refresh` when you're following the MVVM pattern. – Mighty Badaboom Jun 22 '17 at 10:27
  • Not necessarily @MightyBadaboom, when dealing with CollectionViewSource sometime you have to call `CollectionViewSource.GetDefaultView(jobs.ItemsSource).Refresh();` – XAMlMAX Jun 22 '17 at 10:50
  • 1
    Neither the one Refresh nor the other is necessary here. All that's needed is `jobs.ItemsSource = listOfJobs` and the Job members being properties, not fields – Clemens Jun 22 '17 at 11:43
  • @Clemens well spotted! I missed the fact that `Job` has fields not properties! – XAMlMAX Jun 22 '17 at 15:28
  • @MightyBadaboom cause I have as specific that to use the MVC pattern – NoeDag Jun 23 '17 at 10:31
  • 1
    @Clemens I change the Job's fields in properties and works fine, thank you so much! – NoeDag Jun 23 '17 at 12:44

0 Answers0