Binding a string doesn't show up, Binding another type does... WPF

I just started with WPF and databinding. First question on databinding. Databinding on {Binding Periode.Einde} where Einde is of type DateTime works, {Binding Arrangement} where Arrangement is of type Enum works, {Binding Limo.Info} where Info is of type String doesn't work. Somebody has an explanation for that?

<ListView Grid.Column="3" Grid.Row="3" Name="hups" Background="{x:Null}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
        <ListView.ItemTemplate>
            <DataTemplate>
                <DockPanel>
                    <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Background="BlueViolet" Opacity="80" DockPanel.Dock="Left">
                        <Image Source="images\limousine-car-VIP-transport-128.png" Height="50"/>
                        <StackPanel>
                            <TextBlock Text="Starttijdstip:" />
                            <TextBlock Text="{Binding Periode.Begin, ConverterCulture='nl-BE', StringFormat='dddd, dd MMMM yyyy HH:mm:ss'}" FontWeight="Bold" />
                            <TextBlock Text="Stoptijdstip:" />
                            <TextBlock Text="{Binding Periode.Einde, ConverterCulture='nl-BE', StringFormat='dddd, dd MMMM yyyy HH:mm:ss'}" FontWeight="Bold" />
                        </StackPanel>
                    </StackPanel>
                    <StackPanel DockPanel.Dock="Right" Background="BlueViolet" HorizontalAlignment="Right">
                        <TextBlock Text="Limo:" />
                        <TextBlock Text="{Binding Limo.Info}" FontWeight="Bold" />
                        <TextBlock Text="Arrangement:" />
                        <TextBlock Text="{Binding Arrangement}" FontWeight="Bold" />
                    </StackPanel>
                </DockPanel>

            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

Upvotes: 0

Views: 56

Answers (2)

Indeed Limo is null. It's Entity Framework with Lazy Loading I think...

Upvotes: 0

Dean Chalk
Dean Chalk

Reputation: 20471

In your binding expression Text="{Binding Limo.Info}" then if Limo.Info is of type string, then there are only 3 possible scenarios as to why nothing appears in your UI

1) Limo object is null

2) Info string is null or empty

3) Limo.Info is spelled incorrectly, and it's actually something else.

It has to be one of those 3 scenarios. check the objects you are passing into your ListView

Upvotes: 1

Related Questions