priya jain

priya jain

  • NA
  • 76
  • 1.4k

xml parsing . want to access internet on emulator

May 29 2013 6:50 AM
i want  to get text  from text box (which is created in xaml dynamically )within list box,how can i get value please help me out............please help me

namespace helloxml

  <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
 
  <ListBox Height="778" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="24,-45,0,0" Name="listBoxAuthors" VerticalAlignment="Top" Width="444" Loaded="listBox1_Loaded" SelectionChanged="listBoxAuthors_SelectionChanged">
  <phone:WebBrowser HorizontalAlignment="Center" Name="web" Margin="9,121,0,0" />
  <ListBox.ItemTemplate>
  <DataTemplate>
  <StackPanel Orientation="Horizontal">
  <Image Source="{Binding AuthorImage}" Width="150" Stretch="UniformToFill" HorizontalAlignment="Center" />
  <StackPanel Width="370">
  <TextBlock Text="{Binding AuthorName}" FontWeight="Bold" FontSize="22"  Name="id"/>
  <TextBlock Text="{Binding Description}" Name="name" />
  <TextBlock x:Name="srctxtbox" Text="{Binding Source}" />
  </StackPanel>
  </StackPanel>
  </DataTemplate>
  </ListBox.ItemTemplate>
  </ListBox>
  </Grid>



 code behind it

  public partial class MainPage : PhoneApplicationPage
  {
  // Constructor
  public MainPage()
  {
  InitializeComponent();

  SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
  }
  private void listBox1_Loaded(object sender, RoutedEventArgs e)
  {
  var element = XElement.Load("Authors.xml");
  var authors = from var in element.Descendants("Author")
  orderby var.Attribute("AuthorName").Value
  select new Authors
  {
  AuthorId = Convert.ToInt32(var.Attribute("AuthorId").Value),
  AuthorName = var.Attribute("AuthorName").Value,
  AuthorImage = GetImage(var.Attribute("AuthorImage").Value),
  Description = var.Attribute("Description").Value,
  Source = var.Attribute("Source").Value
  };

  listBoxAuthors.DataContext = authors;

  }
  public ImageSource GetImage(string path)
  {
  return new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
  }

  private void listBoxAuthors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {

  var listBoxItem = listBoxAuthors.SelectedItem as ListBoxItem;
  TextBlock nameBlock = listBoxItem.FindName("srctxtbox") as TextBlock;
  MessageBox.Show(nameBlock.Text);
 
 
  }
  }