我有一个关于媒体新闻的 windows phone 项目。在这个项目中,我有一个 panaroma 项目。在我的第一个屏幕上,我从我的 Web API 获得新闻。
我使用长列表选择器来获取这些新闻,但我想将第一条/热门/最新消息放在顶部,并带有它的大图和文本。但是我不能同时在我的网格上正确地给出源LongListSelector
。
简而言之,我想列出我的新闻“一个在另一个之下”,最新/第一个新的将在顶部显示。
这是我尝试过的;
主页.XAML
<!--Panorama item one-->
<phone:PanoramaItem Header="Haberler" Foreground="DarkGreen">
<ScrollViewer VerticalScrollBarVisibility="Auto" Background="White">
<StackPanel Orientation="Vertical">
<Grid x:Name="HeadNew">
<TextBlock x:Name="textBlock14" Text="{Binding Path=TITLE}" TextWrapping="Wrap" Margin="20,0" FontSize="{StaticResource PhoneFontSizeLarge}" Foreground="Black"/>
<Border Width="400" Height="250">
<Border.Background>
<ImageBrush Stretch="Uniform" ImageSource="{Binding Path=MF658370_IMAGE}"/>
</Border.Background>
</Border>
</Grid>
<phone:LongListSelector x:Name="MainLongListSelector" Background="White" Margin="-20,0,0,0" Height="Auto" Loaded="MainLongListSelectorLoaded" SelectionChanged="MainLongListSelectorSelectionChanged" toolkit:TiltEffect.IsTiltEnabled="True">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="12,2,0,4" Height="Auto" Width="Auto">
<Border Width="126" Height="70">
<Border.Background>
<ImageBrush Stretch="Uniform" ImageSource="{Binding Path=MF12670_IMAGE}"/>
</Border.Background>
</Border>
<TextBlock x:Name="textBlock1" Text="{Binding Path=TITLE}" Margin="10,0" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="Black" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</StackPanel>
</ScrollViewer>
</phone:PanoramaItem>
这是 MAINPAGE.XAML.CS
private void MainLongListSelectorLoaded(object sender, RoutedEventArgs e)
{
const string url = "MY_WEB_API_URL";
var hWebRequest = (HttpWebRequest)WebRequest.Create(url);
hWebRequest.Method = "GET";
hWebRequest.BeginGetResponse(MainLongListSelectorLoadCompleted, hWebRequest);
}
private void MainLongListSelectorLoadCompleted(IAsyncResult arr)
{
var request = (HttpWebRequest)arr.AsyncState;
var response = (HttpWebResponse)request.EndGetResponse(arr);
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
_json = streamReader.ReadToEnd();
Headlines = JsonConvert.DeserializeObject<FanatikApiAll.RootObject>(_json);
}
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MainLongListSelector.ItemsSource = Headlines.Headline;
});
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
HeadNew.DataContext = Headlines.Headline;
});
}