19. using System.Linq;
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;
using Windows.UI.ViewManagement;
namespace ViewsTile
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
SizeChanged += DetailPage_SizeChanged;
}
void DetailPage_SizeChanged(object sender, SizeChangedEventArgs e) {
if (ApplicationView.Value == ApplicationViewState.Snapped) {
GridLayout.ColumnDefinitions[0].Width = new GridLength(0);
} else {
GridLayout.ColumnDefinitions[0].Width = new GridLength(1,
GridUnitType.Star);
}
}
}
}
View
20. <TextBlock x:Name="textSnap" Text="Kevin R. Octavian snap" Visibility="Collapsed" />
<TextBlock x:Name="textOthers" Text="Kevin R. Octavian others" />
<VisualStateManager.VisualStateGroups>
<!-- Visual states reflect the application's view state -->
<VisualStateGroup x:Name="ApplicationViewStates">
<VisualState x:Name="FullScreenLandscape"/>
<VisualState x:Name="Filled"/>
<VisualState x:Name="Others">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="textSnap" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="textOthers" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<!-- The back button and title have different styles when snapped -->
<VisualState x:Name="Snapped">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="textSnap" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="textOthers" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
void DetailPage_SizeChanged(object sender, SizeChangedEventArgs e)
{
string stateName = ApplicationView.Value == ApplicationViewState.Snapped ?
"Snapped" : "Others"; VisualStateManager.GoToState(this, stateName, false);
}
View
23. http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882
Create Table
try
{
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
// Create the tables if they don't exist
db.CreateTable<person>();
db.Commit();
db.Dispose();
db.Close();
}
var line = new MessageDialog("Table Created");
await line.ShowAsync();
}
catch
{
}
public class person
{
[MaxLength(5), PrimaryKey]
public String name { get; set; }
[MaxLength(255)]
public String address { get; set; }
[MaxLength(11)]
public Double phone { get; set; }
}
24. http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882
Insert Data
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
// Create the tables if they don't exist
db.Insert(new person()
{
name = txt1.Text.ToString(),
address = txt2.Text.ToString(),
phone = Convert.ToDouble(txt3.Text.ToString()),
}
);
db.Commit();
db.Dispose();
db.Close();
var line = new MessageDialog("Records Inserted");
await line.ShowAsync();
}
25. http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882
Select Data
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
var d = from x in db.Table<person>() select x;
list1.Items.Clear();
foreach (var sd in d)
{
list1.Items.Add(sd.name.ToString());
//list1.Items.Add(sd.address.ToString());
//list1.Items.Add(sd.phone.ToString());
}
db.Dispose();
db.Close();
}
var line = new MessageDialog("All Records Listed");
await line.ShowAsync();
26. http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882
Delete Data
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
db.Delete<person>(list1.SelectedItem.ToString());
var d = from x in db.Table<person>() select x;
list1.Items.Clear();
foreach (var sd in d)
{
list1.Items.Add(sd.name.ToString());
//list1.Items.Add(sd.address.ToString());
//list1.Items.Add(sd.phone.ToString());
}
db.Dispose();
db.Close();
}
var line = new MessageDialog("Selected Item Deleted");
await line.ShowAsync();