Step 3 : The MainPage.xaml file is as in the following code:
Code :
<Page
x:Class="App1.MainPage"
IsTabStop="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App10"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="Green">
<Grid.RowDefinitions>
<RowDefinition Height=".333*"></RowDefinition>
<RowDefinition Height=".333*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".333*"></ColumnDefinition>
<ColumnDefinition Width=".023*"></ColumnDefinition>
<ColumnDefinition Width=".333*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height=".333*"></RowDefinition>
<RowDefinition Height=".333*"></RowDefinition>
<RowDefinition Height=".333*"></RowDefinition>
<RowDefinition Height=".333*"></RowDefinition>
</Grid.RowDefinitions>
<Button Content="Add Value" Background="Red" Grid.Column="2" Margin="276,37,0,21" Click="Button_Click_1"></Button>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Text="Add Book Detail" FontSize="30" FontWeight="ExtraBold" HorizontalAlignment="Center"></TextBlock>
<TextBlock Text="Book Name" FontSize="20" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" FontWeight="Bold"></TextBlock>
<TextBlock Text="Author Name" FontSize="20" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" FontWeight="Bold"></TextBlock>
<TextBlock Text="Book Price" FontSize="20" Grid.Column="0" Grid.Row="3" HorizontalAlignment="Right" FontWeight="Bold"></TextBlock>
<TextBox x:Name="txt1" Grid.Column="2" Width="200" Height="50" HorizontalAlignment="Left" Margin="0,83,0,59" Grid.RowSpan="2"/>
<TextBox x:Name="txt2" Grid.Column="2" Grid.Row="1" Width="200" Height="50" HorizontalAlignment="Left" Margin="0,83,0,59" Grid.RowSpan="2"></TextBox>
<TextBox x:Name="txt3" Grid.Column="2" Grid.Row="2" Width="200" Height="50" HorizontalAlignment="Left" Margin="0,87,0,55" Grid.RowSpan="2"></TextBox>
</Grid>
<GridView x:Name="prodView" Width="600" Height="800" ScrollViewer.VerticalScrollBarVisibility="Visible"
Canvas.Left="240" ItemsSource="{Binding}" Grid.Row="1" Header="Book Detail in GridView" FontSize="40" FontWeight="ExtraBold" Visibility="Collapsed">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding _bookname}" Width="600" Height="50" FontSize="30" FontWeight="Bold" />
<TextBlock Text="{Binding _authorname}" Width="600" Height="50" FontSize="30" FontWeight="Bold" />
<TextBlock Text="{Binding _bookprice}" Width="600" Height="50" FontSize="30" FontWeight="Bold" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
</Page>
Step 4 : First of all you will add a class that will be used to access the data using LINQ; the related code of the class is given below:
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace App1
{
class Class1
{
string bookname;
string authorname;
string bookprice;
public string _bookname
{
get { return bookname; }
set { bookname = value; }
}
public string _authorname
{
get { return authorname; }
set { authorname = value; }
}
public string _bookprice
{
get { return bookprice; }
set { bookprice = value; }
}
public Class1()
{ }
public Class1(string s, string r, string p)
{
bookname = s;
authorname = r;
bookprice = p;
}
}
}