如何判断我的 RSS 阅读器是否由于错误的 RSS 提要或其他原因而无法正常工作?



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

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

这是我的新闻源页面 (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>

这是我的新闻源.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));
}

这是我的新闻源.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 键使导航视图变大变小,而 Tab 键在导航视图中的选项之间移动。我不太确定关键是否是问题所在,但这就是我认为可能的原因。

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

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

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

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

我尝试使用不同的键来启动 Go 方法,但是 Enter 键使导航视图变大变小,而 Tab 键在导航视图中的选项之间移动。我不太确定关键是否是问题所在,但这就是我认为可能的原因。

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

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

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

最新更新