C# :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
public class data
{
public string id { get; set; }
}
List<data> datalist = new List<data>();
int counter = 100000000;
private void button_Click(object sender, RoutedEventArgs e)
{
data add = new data();
counter += 1;
add.id = counter.ToString();
datalist.Add(add);
}
}
XAML :
<Page
x:Class="SocialApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SocialApp1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Button x:Name="button"
Content="Get" HorizontalAlignment="Left" Margin="67,550,0,0" VerticalAlignment="Top" Click="button_Click" Width="368"/>
<ListView Margin="24,0,19,311">
<ListView.ItemTemplate>
<DataTemplate>
<Border CornerRadius="20" Background="DodgerBlue" Height="65">
<StackPanel Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Margin="10" Text="{Binding id}" FontSize="20" />
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>
Hi, I have been trying to do data binding in windows phone 8.1. I post all the code just in case I am missing something. How do I make it to work? because when I deployed it on my phone and when I press the Get
button, it does not do anything.
Desired output :
1) Increment the id
each time the user pressed the the Get
button.
2) Add the new id
in the datalist
.
3) Present it in the ListView.