-1

On HomePage.xaml

 <Page.DataContext>
    <ViewModel:GetTweetVM/>
</Page.DataContext>

Listview

<!--Content-->
    <ListView x:Name="lstHome"
                             Grid.Row="2"
                             Margin="5"
                             ItemInvoked="lstHome_ItemInvoked"
                             ContainerContentChanging="lstHome_ContainerContentChanging" ItemsSource="{Binding statusList}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <Image x:Name="imgThumbnailUser" Source="{Binding}"></Image>

                    <StackPanel Orientation="Vertical" Grid.Column="1">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock x:Name="txtName" Text="{Binding Text}"></TextBlock>
                            <TextBlock x:Name="txtUsername" Text="{Binding User.Name}" Foreground="#CCCCCC"></TextBlock>
                        </StackPanel>
                        <TextBlock x:Name="txtContentMessage" Text="{Binding User.Categories.Name}" TextTrimming="CharacterEllipsis" Foreground="#CCCCCC"></TextBlock>
                    </StackPanel>

                    <TextBlock x:Name="txtDateTime" Text="{Binding}" Foreground="#CCCCCC"></TextBlock>

                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </control:ListView>

In GetTweetVM

 public class GetTweetVM
{
    TwitterContext twitter;

    public List<Status> statusList { get; set; }
    public GetTweetVM()
    {
        statusList = new List<Status>();
        if (SharedState.Authorizer != null)
        {
            twitter = new TwitterContext(SharedState.Authorizer);
            GetTweet();
        }
        else
            return;

    }

    public async void GetTweet()
    {
        //base.GetTweet();
        var objectStatus = await (from status in twitter.Status
                            where status.Type == LinqToTwitter.StatusType.Home && status.Count==10
                            select status).ToListAsync();
        foreach(var item in objectStatus)
        {
            statusList.Add(item);
        }
        string t = statusList[0].Text;
    }
}

The results :

  1. string t will get value from statusList->"fadsvs.........."
  2. On xaml that it do not binding to view.
  3. Listview is no data.

I don't know where it is wrong? Please help me to fix it.

Clemens
  • 123,504
  • 12
  • 155
  • 268
  • 1
    For starters, your `List` should really be an `ObservableCollection` or else modifications to the list will not update the `ListView`. – Decade Moon Oct 23 '16 at 00:55
  • Can you custome my code? For better?. I'm leaning it – Delikatessen Berglunds Oct 23 '16 at 01:14
  • I don't understand your question. Given your lack of proficiency in English, you should take more time with the specifics. Make sure you include a good [mcve] that reliably reproduces the problem, and also make sure that you include _exact_ quotes of any error messages, exceptions, etc. that occur (preferably also in English...set the UI culture to "en" if you need to). Code and machine-generated output is universal and much easier to understand when there's otherwise a language barrier. – Peter Duniho Oct 23 '16 at 02:25

2 Answers2

1

If I understand properly you have notification issue from ViewModel to View

Try below

public ObservableCollection<Status> statusList { get; set; }

ObservableCollection will ensure notification to UI when any item is added.

More on ObservableCollection

What is the use of ObservableCollection in .net?

Hope this helps.

Community
  • 1
  • 1
0

Definitely you should replace:

public List<Status> statusList { get; set; }  

with:

public ObservableCollection<Status> statusList { get; set; }

When ever you work with MVVM and data binding you should use ObservableCollection so you could get UI notifications when list is changed. Note that UI notifications will not be triggered when some object properties in list has changed only the list itself(elements have been added/removed or moved in the list). Its because ObservableCollection trigger events only when collection is changed not and object properties in the list.

Hope it helps

Dan
  • 448
  • 10
  • 20