Andrew Simpson
Andrew Simpson

Reputation: 7324

text not showing in my listview

obviously i am doing something wrong as I have used this type of control in this way before.

My text is not displaying in my listview. I can double click the item and get its value(s) but I cannot see it. You would think it would be a simple style setting and maybe it has been set elsewhere in my appp.xaml but it is not.

This is my markup:

<UserControl.Resources>
    <ResourceDictionary>
        <Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="Visibility" Value="Collapsed" />
        </Style>
        <DataTemplate x:Key="value1Template">
            <TextBlock TextAlignment="Left" Text="{Binding Path=CustomerName}"/>
        </DataTemplate>
    </ResourceDictionary>
</UserControl.Resources>


<ListView x:Name="lstActiveJobs" Grid.Row="1" Grid.Column="0" Foreground="Black" MouseDoubleClick="lstActiveJobs_MouseDoubleClick" >
    <ListView.ContextMenu>
        <ContextMenu>
            <MenuItem Header="View"
                        Click="cmView"     
                        Command="{Binding RemoveItem}"
                        CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, 
                       Path=PlacementTarget.SelectedItem}" />                   
        </ContextMenu>
    </ListView.ContextMenu>
    <ListView.View>
        <GridView AllowsColumnReorder="False" ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}">
            <GridViewColumn Header="CustomerName"  Width="100"  CellTemplate="{StaticResource value1Template}"  />
        </GridView>
    </ListView.View>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"  />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

part of my code behind:

lstActiveJobs.ItemsSource = ActiveState.JobsActive;

public static ObservableCollection<JobTicker> JobsActive = new ObservableCollection<JobTicker>();

point to note is:

ActiveState.JobsActive does have a record/item

My Model:

public  class JobTicker
{
    public string CustomerRef;
    public string JobRef;
    public string CustomerName;
}

Upvotes: 0

Views: 1280

Answers (1)

dkozl
dkozl

Reputation: 33364

Field is not a valid binding source

You can bind to public properties, sub-properties, as well as indexers, of any common language runtime (CLR) object.

so you need to convert your fields into properties

public class JobTicker
{
    public string CustomerRef { get; set; }
    public string JobRef { get; set; }
    public string CustomerName { get; set; }
}

Upvotes: 3

Related Questions