Question

I need to do application for Windows Phone for school project. I've followed tutorial to do RSS reader, but it doesn't work and I don't know why.

I'm getting following error (after it runs):

System.Windows.Data Error: BindingExpression path error: 'Items' property not found on 'Expression.Blend.SampleData.JustTestingData.JustTestingData' 'Expression.Blend.SampleData.JustTestingData.JustTestingData' (HashCode=12963143). BindingExpression: Path='Items' DataItem='Expression.Blend.SampleData.JustTestingData.JustTestingData' (HashCode=12963143); target element is 'System.Windows.Controls.ListBox' (Name='FeedContent'); target property is 'ItemsSource' (type 'System.Collections.IEnumerable')..

Here is my .cs file:

public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);
    }

    public void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        WebClient wc = new WebClient();
        wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
        wc.OpenWriteAsync(new Uri("http://www.twojapogoda.pl/wiadomosci.xml"));
    }

    public void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        SyndicationFeed feed;
        using (XmlReader reader = XmlReader.Create(e.Result))
        {
            feed = SyndicationFeed.Load(reader);
            FeedContent.ItemsSource = feed.Items;

        }
    }  
}

Here is my xaml:

<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Syndication="clr-namespace:System.ServiceModel.Syndication;assembly=System.ServiceModel.Syndication"
    x:Class="JustTestIt.MainPage"
    mc:Ignorable="d"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="ItemTemplate">
            <StackPanel>
                <CheckBox IsChecked="{Binding date, Mode=TwoWay}"/>
                <TextBlock Text="{Binding title}"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="ItemTemplate1">
            <StackPanel>
                <CheckBox IsChecked="{Binding date, Mode=TwoWay}"/>
                <TextBlock Text="{Binding title}"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="ItemTemplate2">
            <StackPanel Width="381">
                <TextBlock Text="{Binding title}" FontSize="32" Foreground="#FFFF8B00" Margin="0,0,10,0" FontFamily="Segoe WP Semibold"/>
                <TextBlock Text="{Binding date}" Foreground="White" FontFamily="Segoe WP Light"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="SyndicationItemTemplate">
            <StackPanel>
                <TextBlock Text="{Binding Title.Text}"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="SyndicationItemTemplate1">
            <StackPanel>
                <TextBlock Text="{Binding Title.Text}"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="SyndicationItemTemplate2">
            <StackPanel>
                <TextBlock Text="{Binding Title.Text}"/>
            </StackPanel>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource ResourceKey="PhoneFontSizeNormal"/>
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource ResourceKey="PhoneForegroundBrush"/>
    </phone:PhoneApplicationPage.Foreground>
    <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Source={StaticResource JustTestingData}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <phone:Panorama Foreground="White" FontFamily="Segoe WP Light" Background="Black">
            <phone:Panorama.Title>
                <TextBlock Text="JustTest it!"/>
            </phone:Panorama.Title>
            <phone:PanoramaItem x:Name="headers" CacheMode="{x:Null}" Header="">
                <phone:PanoramaItem.RenderTransform>
                    <TranslateTransform/>
                </phone:PanoramaItem.RenderTransform>
                <Grid Margin="0">
                    <ListBox HorizontalAlignment="Left" ItemTemplate="{StaticResource ItemTemplate2}" ItemsSource="{Binding Collection}" VerticalAlignment="Top" Width="410"/>
                </Grid>
            </phone:PanoramaItem>
            <phone:PanoramaItem x:Name="articles" CacheMode="{x:Null}" Header="" d:DataContext="{d:DesignData /SampleData/SyndicationFeedSampleData.xaml}">
                <phone:PanoramaItem.RenderTransform>
                    <TranslateTransform/>
                </phone:PanoramaItem.RenderTransform>
                <Grid>
                    <ListBox x:Name="FeedContent" HorizontalAlignment="Left" ItemTemplate="{StaticResource SyndicationItemTemplate2}" ItemsSource="{Binding Items}" VerticalAlignment="Top"/>
                </Grid>
            </phone:PanoramaItem>
        </phone:Panorama>
    </Grid>
</phone:PhoneApplicationPage>

What am I doing wrong, that nothing loads from source? I'm using blend and visual studio 2013.

Was it helpful?

Solution 2

The problem with the error concerned with missing property (in the code you have provided) explained AMR.

Also you should be aware that the line in the code:

FeedContent.ItemsSource = feed.Items;

would destroy the Binding you have defined in xaml.

The problem why your FeedContent isn't filled is concerned with lines:

wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenWriteAsync(new Uri("http://www.twojapogoda.pl/wiadomosci.xml"));

You are subscribing to the event OpenReadCompleted, but running OpenWriteAsync() method. Your event won't get fired at all (and you probably also won't be able to write to this Uri). Change it to:

wc.OpenReadAsync(new Uri("http://www.twojapogoda.pl/wiadomosci.xml"));

then your event will be fired and SyndicationFeed loaded.

OTHER TIPS

Your error is on this line

 <ListBox x:Name="FeedContent" HorizontalAlignment="Left" ItemTemplate="{StaticResource 
SyndicationItemTemplate2}" ItemsSource="{Binding Items}" VerticalAlignment="Top"/>

The error is right here

ItemsSource="{Binding Items}" 

Its saying it cant see a property named "Items"

This could be for a number of reasons. I need to see all of your CS file to give you a more specific answer

If this IS all of your cs file then the there is a HUGE problem. You have no properties....

You could start by adding this.

public ObservableCollection Items {get;set;}

Also it doesn't appear that you are setting the datacontext.

Above InitializeComponent do this.

this.DataContext = this;

Edit

Based on further evaluation of your CS file and some creative extrapolation it looks like you need to do the following.

Make your SyndicationFeed object a property

private SyndicationFeed _feed;
public SyndicationFeed feed {get{return _feed;} set{_feed = value; OnPropertyChanged("feed");} 

Set your datacontext to

this.Datacontext = feed;

implement

INotifyPropertyChanged

Add a property Changed event handler

     protected void OnPropertyChanged(string name)
      {
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null)
          {
              handler(this, new PropertyChangedEventArgs(name));
          }
      }

I am pretty sure your SyndicationFeed class needs to implement INotifyPropertyChanged also.

Either of the above two solutions should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top