ListBox.ItemTemplate error

Omega Ra

Senior Member
Apr 1, 2009
676
15
48
Metuchen, NJ
hey guys I am getting an error when I am trying to put a twitter feed in my blog app. The error says

“The attachable property ‘ItemTemplate’ was not found in type ‘ListBox’.”

what does this mean. Here is the code that I put in my listbox on the Xaml.

Code:
<ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Height="132">
                <Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
                <StackPanel Width="370">
                    <TextBlock Text="{Binding UserName}" Foreground="#FF2276BB" FontSize="28" />
                    <TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" />
                    <HyperlinkButton Content="{Binding TweetSource}" Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="18" Foreground="#FF999999" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
any help would be appreciated.
 

Omega Ra

Senior Member
Apr 1, 2009
676
15
48
Metuchen, NJ
http://blog.objectgraph.com/index.php/2010/03/26/how-to-create-a-twitter-client-on-windows-phone-7/

I am using that site as a guide and putting it in the Wordpress Starter Kit I added a panarama item called Twitter, added a list box and a button and a TextBlock (the text block says OmegaRa) and the buttons says refresh. I am at work currently, so I can't post the rest of my code...

edit: if it matters I named the listbox Twitterfeed, I know I had to alter a couple spots with that to get rid of errors. Plus the original code is for 7.0, in VS2010, I right clicked on the Solution and clicked Upgrade to 7.1...
 
Last edited:

sensboston

Recognized Developer
Nov 18, 2009
2,142
797
193
Boston, MA
Seems like this toolkit has a different assemblies for 7.0 and 7.1 (located at sl3-wp & sl4-windowsphone71 folders), check your project references for correct library (7.1).
 
  • Like
Reactions: Omega Ra

sensboston

Recognized Developer
Nov 18, 2009
2,142
797
193
Boston, MA
Solution Explorer (on your right) -> References -> click on assembly and check properties. Press Del to remove assembly. Right click and press "Add assembly" from the context menu.

P.S. But before start coding I'm strongly recommend you to RTFM (Read The Following Manual, not the "fu%?ng" one :D ). Download/buy and read a good manual for Visual Studio and .NET first...
 
  • Like
Reactions: Omega Ra

Omega Ra

Senior Member
Apr 1, 2009
676
15
48
Metuchen, NJ
That would probably be a good idea LOL. I just like figuring it out sometimes though, but it would probably go faster if I read something about it first lol.

edit: I will try looking at that when I get home from work and after my daughters birthday dinner lol
 

Omega Ra

Senior Member
Apr 1, 2009
676
15
48
Metuchen, NJ
progress, fixed that part forgot the
Code:
 <listbox></listbox>
surrounding it, but when I hit refresh...is doen't get my feed, lol it says something about wordpress starter kit + tweet or something lol.

here is the code for the button
Code:
    private void button3_Click(object sender, RoutedEventArgs e)
        {
            WebClient twitter = new WebClient();
    twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
    twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + tbUsername.Text));
}
        void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                XElement element = XElement.Parse(e.Result);
                TwitterFeed.ItemsSource = from tweet in element.Descendants("status")
                                          select new Tweet
                                          {
                                              UserName = tweet.Element("user").Element("screen_name").Value,
                                              Message = tweet.Element("text").Value,
                                              ImageSource = tweet.Element("user").Element("profile_image_url").Value,
                                              TweetSource = FormatTimestamp(tweet.Element("source").Value, tweet.Element("created_at").Value)
                                          };
            }
            catch (Exception)
            {
             
            }
        }
        public class Tweet
        {
            public string UserName { get; set; }
            public string Message { get; set; }
            public string ImageSource { get; set; }
            public string TweetSource { get; set; }
        }
        private string StripHtml(string val)
        {
            return System.Text.RegularExpressions.Regex.Replace(HttpUtility.HtmlDecode(val), @"<[^>]*>", "");
        }
        private string DateFormat(string val)
        {
            string format = "ddd MMM dd HH:mm:ss zzzz yyyy";
            DateTime dt = DateTime.ParseExact(val, format, System.Globalization.CultureInfo.InvariantCulture);
            return dt.ToString("h:mm tt MMM d");
        }
        private string FormatTimestamp(string imageSource, string date)
        {
            return DateFormat(date) + " via " + StripHtml(imageSource);
        }
        }
     
        }
what the screen says when I hit refresh is WordpressStarterKit.Mainpage+Tweet, and I notice that the button and the Text Block stay on the screen no matter if I pan or not....
 
Last edited:

Omega Ra

Senior Member
Apr 1, 2009
676
15
48
Metuchen, NJ
If I change
Code:
twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + tbUsername.Text));
to

Code:
twitter.DownloadStringAsync(new Uri"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=OmegaRa" );
would that fix it? I am just curious to see if I am right..