【问题标题】:How to tell if my RSS reader isn't working because of a bad RSS feed or because of something else?如何判断我的 RSS 阅读器是否因为 RSS 提要错误或其他原因而无法工作?
【发布时间】:2019-04-23 12:23:28
【问题描述】:

我在显示来自 RSS 阅读器的 XML 数据时遇到问题,我尝试了来自许多不同来源的许多不同 RSS 提要,但我无法显示任何内容。

我正在尝试获取俄罗斯新闻 RSS 源,我也使用了 BBC 新闻源,但我无法获取任何数据,我无法确定它是 RSS 源端的东西还是我端的东西(代码,或者来自 Go 方法的东西)。我使用了一些示例 RSS 提要代码,它在我的计算机上正常工作,所以我只是在不同的阅读器上尝试了它,它甚至根本不会显示任何内容。

这是我的 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>

这是我的 NewsFeed.cs 文件:

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));
            }

这是我的 NewsFeed.cs 文件(支持类):

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);
            }
        }

    }

}

我尝试使用不同的键来启动 Go 方法,但是 Enter 键使 NavigationView 变得越来越小,而 Tab 键在 NavigationView 的选项之间移动。我不太确定关键是否是问题所在,但我认为可能是这样。

【问题讨论】:

    标签: c# xaml uwp rss


    【解决方案1】:

    如果您的意思是按 Enter 时无法获取任何数据,问题就在这里:

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

    如果您想调用Go 方法并在按Enter 时进入Load 方法代码块。您需要更改代码:

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

    我尝试使用不同的键来启动 Go 方法,但是 Enter 键使 NavigationView 变得越来越小,而 Tab 键在 NavigationView 的选项之间移动。我不太确定关键是否是问题所在,但我认为可能是这样。

    这是设计使然。如果当前页面没有焦点元素,当你按下Enter时,它会自动寻找下一个焦点元素并使其成为焦点。您可以通过编程手动关注某个元素来解决此问题。

    例如,您可以在页面加载时关注ItemsControl

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

    【讨论】:

    • 谢谢,成功了!我很感激,但不知道必须将重点放在具体的部分上。
    猜你喜欢
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多