This is my xaml:
<phone:PhoneApplicationPage
x:Class="FinanciaLounge.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignData SampleData/News_MainViewModelSampleData.xaml}"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<Grid HorizontalAlignment="Left" Name="menulist" Width="478">
<Grid.Background>
<ImageBrush ImageSource="Images/bg.png" Stretch="UniformToFill" />
</Grid.Background>
<Grid HorizontalAlignment="Left" x:Name="MenuList1" >
<Grid Width="380" HorizontalAlignment="Left" >
<Grid.RowDefinitions>
<RowDefinition Height="76"/>
<RowDefinition Height="70"/>
<RowDefinition Height="30" />
<RowDefinition Height="590" />
</Grid.RowDefinitions>
<Grid x:Name="ContentPane7" Grid.Row="0" Margin="0,0,0,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="350" />
</Grid.ColumnDefinitions>
<Grid.Background>
</Grid.Background>
<!--<Image Source="Images/
[email protected]" Height="40" Grid.Column="1" Width="320" HorizontalAlignment="Left" Stretch="Fill" Margin="10,15,0,15"></Image>-->
<TextBox Height="60" Foreground="Black" Width="320" HorizontalAlignment="Left" Margin="10,15,0,0" Name="textBox1" BorderThickness="0" VerticalAlignment="Top" GotFocus="textBox1_GotFocus">
<TextBox.Background>
</TextBox.Background>
</TextBox>
</Grid>
<Grid x:Name="ContentPane8" Grid.Row="1" Margin="0,0,0,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="350" />
</Grid.ColumnDefinitions>
<Grid.Background>
<ImageBrush ImageSource="Images/topbar.png" Stretch="Fill" />
</Grid.Background>
<!--<Image Source="Images/
[email protected]" Stretch="None" Tap="Image_Tap" ></Image>-->
<Image Source="Images/flogo.png" Grid.Column="1" Width="270" HorizontalAlignment="Left" Stretch="Fill" Margin="10,15,0,15" />
</Grid>
<Grid x:Name="ContentPane9" Grid.Row="2" Margin="0,0,0,0" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.Background>
</Grid.Background>
<TextBlock Grid.ColumnSpan="2" Height="35" HorizontalAlignment="Left" Margin="10,0,0,0" Name="textBlock3" Text="MENU" VerticalAlignment="Top" />
</Grid>
<Grid x:Name="ContentPane10" Grid.Row="3" Margin="0,0,0,0">
<ListBox x:Name="MenuListBox" ItemsSource="{Binding Items1}" Width="380" Grid.Row="3" SelectionChanged="MenuListBox_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="59" Orientation="Horizontal">
<StackPanel.Background>
<ImageBrush ImageSource="Images/
[email protected]" Stretch="UniformToFill"></ImageBrush>
</StackPanel.Background>
<Image Source="{Binding Picture2}" Margin="10,0,0,0" Name="image1" Stretch="None" Width="40"></Image>
<TextBlock Text="{Binding LineFour}" Margin="10,0,0,0" VerticalAlignment="Center" Name="text1" Foreground="White" Width="220" FontSize="24" ></TextBlock>
<Image Source="{Binding Picture3}" Margin="15,0,0,0" Name="image3" Stretch="None"></Image>
<TextBlock Text="{Binding LineFive}" Margin="-30,0,0,0" Name="text2" Foreground="White" FontSize="19" TextWrapping="Wrap" Width="350" VerticalAlignment="Center" ></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
</Grid>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush ImageSource="Images/bg.png" Stretch="UniformToFill" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="ContentPanel" Grid.Row="0" Margin="0,0,0,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="380" />
</Grid.ColumnDefinitions>
<Grid.Background>
</Grid.Background>
<Image Source="Images/flogo.png" Grid.Column="1" Width="300" HorizontalAlignment="Left" Stretch="Fill" Margin="10,15,0,15" />
</Grid>
<Grid x:Name="ContentPane2" Grid.Row="1" Margin="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
<ColumnDefinition Width="380" />
</Grid.ColumnDefinitions>
<Grid.Background>
</Grid.Background>
<Image HorizontalAlignment="Right" Source="Images/newsicon.png" Stretch="None" ></Image>
<TextBlock Grid.Column="1" Height="30" HorizontalAlignment="Left" Margin="10,10,0,0" Name="textBlock1" Text="News" Foreground="#3a568D" FontWeight="Bold" FontSize="24" VerticalAlignment="Top" />
</Grid>
<Grid x:Name="ContentPane3" Grid.Row="2" Margin="0,0,0,0" DataContext="{Binding}">
<ListBox x:Name="MainListBox" Height="640" DataContext="{Binding}" ItemsSource="{Binding list1}" SelectionChanged="MainListBox_SelectionChanged" Width="478">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="stack1" Width="478" Height="110" Orientation="Horizontal">
<StackPanel Width="90" Height="110" Orientation="Vertical">
<Image Source="{Binding Picture}" HorizontalAlignment="Left" Margin="10,5,0,0" Name="image1" />
</StackPanel>
<StackPanel Width="360" Height="100" Orientation="Vertical">
<StackPanel.Background>
<ImageBrush ImageSource="Images/newsdetail.png"/>
</StackPanel.Background>
<StackPanel Width="360" Height="40" Orientation="Horizontal">
<TextBlock Text="{Binding title}" Margin="10,0,0,0" x:Name="listtext1" TextWrapping="Wrap" Foreground="#3a568d" FontWeight="Bold" FontSize="22" VerticalAlignment="Top" ></TextBlock>
<TextBlock Text="{Binding LineOne}" Foreground="Gray" Margin="20,5,0,0" FontSize="18" x:Name="listtext3" HorizontalAlignment="Right" ></TextBlock>
</StackPanel>
<StackPanel Width="360" Height="100">
<TextBlock Text="{Binding LineThree}" Margin="10,0,0,0" x:Name="listtext2" Foreground="Black" FontSize="18" TextWrapping="Wrap" Width="400" VerticalAlignment="Center" ></TextBlock> </StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
</Grid>
<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
</phone:PhoneApplicationPage>
I want to bind the data in list1 to MainListbox, so that i can show the news.
i'm not able to bind the list1 to MainListBox....
m new to windows phone development, can anybody help???? and this is my xaml.cs code:
namespace FinanciaLounge
{
public partial class Page1 : PhoneApplicationPage
{
int a = 0;
string json = "";
RootObject newss { get; set; }
public Page1()
{
InitializeComponent();
DataContext = App.ViewModel2;
this.Loaded += new RoutedEventHandler(Page1_Loaded);
}
private void Page1_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel2.IsDataLoaded)
{
App.ViewModel2.LoadData();
}
string url = @"http://www.financialounge.com/YUCOM/?action=latest_news";
HttpWebRequest hWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
hWebRequest.Method = "GET";
hWebRequest.BeginGetResponse(Response_Completed, hWebRequest);
}
public void Response_Completed(IAsyncResult result)
{
HttpWebRequest request = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
{
json = streamReader.ReadToEnd();
newss = JsonConvert.DeserializeObject<RootObject>(json);
string date1;
date1 = newss.latest_news.extractionDate.ToString();
List<Item> list1 = new List<Item>();
foreach (var item in newss.latest_news.items)
{
string itmid = item.id;
string itmcon = item.content;
string itmpub = item.pubDate;
string itmtitle = item.title;
list1.Add(new Item(itmid,itmcon,itmpub,itmtitle));
}
MainListBox.DataContext = list1;
//MainListBox.ItemsSource = list1;
//MainListBox.DataContext = newss.latest_news;
}
}
public class Item
{
public string id { get; set; }
public string pubDate { get; set; }
public string title { get; set; }
public string content { get; set; }
public Item(string itmid, string itmcon, string itmpub, string itmtitle)
{
this.id = itmid;
this.content = itmcon;
this.pubDate = itmpub;
this.title = itmtitle;
}
}
public class LatestNews
{
public string extractionDate { get; set; }
public List<Item> items { get; set; }
}
public class RootObject
{
public LatestNews latest_news { get; set; }
}
private void Image_Tap(object sender, GestureEventArgs e)
{
a = a + 1;
if (a % 2 != 0)
{
LayoutRoot.Width = 100;
LayoutRoot.HorizontalAlignment = HorizontalAlignment.Right;
}
else
{
LayoutRoot.Width = 478;
LayoutRoot.HorizontalAlignment = HorizontalAlignment.Left;
}
}
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// If selected index is -1 (no selection) do nothing
if (MainListBox.SelectedIndex == -1)
return;
// Navigate to the new page
NavigationService.Navigate(new Uri("/News_single.xaml?selectedItem=" + MainListBox.SelectedIndex, UriKind.Relative));
// Reset selected index to -1 (no selection)
MainListBox.SelectedIndex = -1;
}
private void MainListBox_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
I want to bind the data in list1 to MainListbox, so that i can show the news.
i'm not able to bind the list1 to MainListBox....
m new to windows phone development, can anybody help????