Windows Phone 7 Empty data message for list?

OK, so I'm trying to get a very simple message to display when the collection is empty. It only works on the page with turning pages after the second time when I visit ... I would really like an elegant solution. It seems to me that I missed something really simple.

inside my ViewModel ...

    private bool _IsDataLoaded;
    public bool IsDataLoaded
    {
        get
        {
            return _IsDataLoaded;
        }
        set
        {
            _IsDataLoaded = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("IsDataLoaded"));
            }
        }
    }

    public string EmptyMessage
    {
        get
        {
            if (IsDataLoaded)
            {
                return "No Tips for this Venue.";
            }
            else
            {
                return "";
            }
        }
    }

    ........

     void clientGetTips_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        ...

        this.IsDataLoaded = true;
    }

here is xaml ....

    <TextBlock Text="{Binding EmptyMessage}" Visibility="{Binding Converter={StaticResource CollectionLengthToVisibilityConverter1}, Path=VitalSigns.Count}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" />
+3
source share
1 answer

You also need to raise a change event for your EmptyMessage, for example:

public bool IsDataLoaded
{
    get
    {
        return _IsDataLoaded;
    }
    set
    {
        _IsDataLoaded = value;
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs("IsDataLoaded"));
            PropertyChanged(this, new PropertyChangedEventArgs("EmptyMessage"));
        }
    }
}
+3
source

All Articles