Steve
Steve

Reputation: 11963

Image not showing after collapsed

I am running into a strange situation where the image won't show up if its visibility is first set to collapsed and latter set to visible through binding.

<ListView Grid.Row="0" ItemsSource="{Binding SystemCheckEntries}">
            <GridViewColumn DisplayMemberBinding="{Binding State}" />
            <GridViewColumn>
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Image Source="info.png" 
                               Height="14" 
                               ToolTip="{Binding Message}"
                               Visibility="{Binding Message, Converter={StaticResource StringNullOrEmptyToVisibilityConverter}}"/>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

Converter:

public class StringNullOrEmptyToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return string.IsNullOrEmpty((string) value) ? Visibility.Collapsed : Visibility.Visible;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

if I use Visibility.Collapsed in converter then the result looks like
enter image description here

and if I open up visual tree to check the property of the image
enter image description here
which says its suppose to be "Visible" (but apparently not)

If I use Visibility.Hidden in converter then the result looks like
enter image description here

Which is exactly what I wanted. But then I don't want the icon to take up extra space when its not showing.

So .. why is this happening?

Upvotes: 0

Views: 150

Answers (1)

brunnerh
brunnerh

Reputation: 184441

Some conjecture: The first items have no width (because they are collapsed), the ListView sets the column width to 0. New items are added that have an image but it's not shown because the column has no width.

Edit: Just confirmed this behaviour.

Upvotes: 1

Related Questions