I'm having trouble displaying XML data from an RSS Reader and I've tried many different RSS feeds from many different sources and I can't get anything displayed.

I'm trying to get Russian News RSS Feeds and I have also used BBC News Feed and I can't get any data pulled down and I can't decide if it's something on the RSS Feed's end or something on my end (code, or something from the Go method). I've used some sample RSS feed code and it worked on my computer correctly so I just tried it with different readers and it won't even bring up anything at all.

This is my NewsFeedPage (XAML):

 <Grid>
        <NavigationView x:Name="NavView"
                        ItemInvoked="NavView_ItemInvoked"
                        SelectionChanged="NavView_SelectionChanged"
                        Loaded="NavView_Loaded"
                        Canvas.ZIndex="0" Background="White" Margin="0,0,222,10" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <NavigationView.MenuItems>
                <NavigationViewItem x:Name="HomeNav" Content="Home" Tag="Home" Icon="Home"/>
                <NavigationViewItemSeparator Height="100"></NavigationViewItemSeparator>
                <NavigationViewItemHeader Content="Separate Pages"/>
                <NavigationViewItem x:Name="AttractionsNav" Content="Attractions" Tag="Attractions" Icon="World"/>
                <NavigationViewItem x:Name="PlacestoEatNav" Content="Places to Eat" Tag="PlacesToEat" Icon="Like"/>
                <NavigationViewItem x:Name="MapNav" Content="Map" Tag="Map" Icon="Map"/>
                <NavigationViewItem x:Name="PhotosNav" Content="Photos" Tag="Photos" Icon="Camera"/>
                <NavigationViewItem x:Name="NewsNav" Content="News" Tag="News" Icon="Globe"/>
                <NavigationViewItem x:Name="WeatherNav" Content="Weather" Tag="weather" Icon="CalendarWeek"/>
            </NavigationView.MenuItems>


            <Frame x:Name="ContentFrame" Margin="24,24,0,24" Width="1916" VerticalAlignment="Stretch">
                <Frame.ContentTransitions>
                    <TransitionCollection>
                        <NavigationThemeTransition/>
                    </TransitionCollection>
                </Frame.ContentTransitions>
            </Frame>

        </NavigationView>

        <Grid HorizontalAlignment="Stretch" Margin="348,0,0,0" VerticalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MaxWidth="1000"/>
                <ColumnDefinition MinWidth="500"/>
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0" Padding="12,12,12,0" KeyDown="Go_KeyDown">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <TextBox Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="Firebrick" Text="BBC News" FontSize="28" Background="White" IsReadOnly="True"/>
                <TextBox Grid.Row="1" Name="value" VerticalAlignment="Center" TextWrapping="Wrap" Text="Press ENTER key to see latest new stories below. Click on a blue web address to see story details on the right." IsReadOnly="True"/>

                <ScrollViewer Grid.Row="2" Margin="20" BorderThickness="0">
                    <ItemsControl Name="display">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Background="GhostWhite">
                                    <TextBlock FontSize="24" TextWrapping="Wrap" Text="{Binding Path=Title.Text}" Foreground="Firebrick" Margin="2,2,10,2"/>
                                    <TextBlock Text="{Binding Path=PublishedDate}" Foreground="Firebrick"/>
                                    <TextBlock Text="{Binding Path=Summary.Text}" TextWrapping="WrapWholeWords" Foreground="Black"/>
                                    <TextBlock x:Name="address" Tapped="Address_OnTapped" Text="{Binding Path=Links[0].Uri}" Foreground="Blue">
                                    </TextBlock>
                                    <TextBlock></TextBlock>
                                    <Rectangle x:Name="BorderBottom" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Fill="DarkSalmon"/>
                                </StackPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>


                    </ItemsControl>
                </ScrollViewer>

            </Grid>

            <Grid Grid.Column="1">
                <WebView x:Name="ArticleWebView"/>
            </Grid>

        </Grid>


    </Grid>
</Page>

This is my NewsFeed.cs file:

public sealed partial class NewsFeedPage : Page
    {
        public NewsFeedPage()
        {
            this.InitializeComponent();
        }

        public NewsFeed MyFeed = new NewsFeed();

        public string address = "http://feeds.bbci.co.uk/news/rss.xml";



        private void Address_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            var tblk = sender as TextBlock;
            Uri websiteuri = new Uri(tblk.Text);
            ArticleWebView.Navigate(websiteuri);
        }

        private void Go_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            MyFeed.Go(ref display, address, e);
        }

        private void NavView_Loaded(object sender, RoutedEventArgs e)
        {

        }


        private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
        {
            if (args.IsSettingsInvoked)
            {
                Frame.Navigate(typeof(SettingsPage));
            }

This is my NewsFeed.cs file (supporting class):

namespace SEMESTER_PROJECT
{
    public class NewsFeed
    {
        private async void Load(ItemsControl list, Uri uri)
        {
            SyndicationClient client = new SyndicationClient();

            SyndicationFeed feed = await client.RetrieveFeedAsync(uri);

            if (feed != null)
            {
                foreach (SyndicationItem item in feed.Items)
                {
                    list.Items.Add(item);
                }
            }
        }

        public void Go(ref ItemsControl list, string value, KeyRoutedEventArgs args)
        {
            if (args.Key == Windows.System.VirtualKey.CapitalLock)
            {
                try
                {
                    Load(list, new Uri(value));

                }
                catch
                {
                    Console.Write("Yeah it didn't work for some reason.");
                }
                list.Focus(FocusState.Keyboard);
            }
        }

    }

}

I've tried doing different keys to start the Go method, but the Enter key makes the NavigationView bigger and smaller while the Tab key moves between the options in the NavigationView. I'm not quite sure if the key is the problem, but that's what I think it might be.

1 Answers

0
Xavier Xie - MSFT On Best Solutions

If you meant that you cannot get any data when press Enter, the issue is here:

if (args.Key == Windows.System.VirtualKey.CapitalLock)

If you want to call the Go method and go into the Load method code block when you press Enter. You need to change the code:

if (args.Key == Windows.System.VirtualKey.Enter)

I've tried doing different keys to start the Go method, but the Enter key makes the NavigationView bigger and smaller while the Tab key moves between the options in the NavigationView. I'm not quite sure if the key is the problem, but that's what I think it might be.

It's by design. If there's no focused element on current page, it will automatically find next focusable element and make it focus when you press Enter. You could manually focus on some one element by programmatic to solve this issue.

For example, you could focus on the ItemsControl when the page is loaded.

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    display.Focus(FocusState.Programmatic);
}