Building Live Search & Sharing Contracts on Windows 8 Metro LOB Enterprise Apps


The Windows 8 Metro LOB Enterprise apps remain incomplete without the features of live Search & Sharing Contracts with other Metro apps as Share Source to Share Targets. The Sharing contracts helps to connect with live notifications , scheduling application data in either text, email with other Sharing Target apps.

  • Lets check to implement a Share Contract on a Metro LOB Enterprise app.

  • Add the following code for the Sharing contract :

protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)

{

// Allow saved page state to override the initial item to display

if (pageState != null && pageState.ContainsKey(“SelectedItem”))

{

navigationParameter = pageState[“SelectedItem”];

}

// TODO: Create an appropriate data model for your problem domain to replace the sample data

var item = RecipeDataSource.GetItem((String)navigationParameter);

this.DefaultViewModel[“Group”] = item.Group;

this.DefaultViewModel[“Items”] = item.Group.Items;

this.flipView.SelectedItem = item;

// Register for the DataRequested events

DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;

}

void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)

{

    var request = args.Request;

    var item = (RecipeDataItem)this.flipView.SelectedItem;

request.Data.Properties.Title = item.Title;

request.Data.Properties.Description = “Recipe ingredients and directions”;

  //Share recipe text

     var recipe = “\r\nINGREDIENTS\r\n”;

recipe += String.Join(“\r\n”, item.Ingredients);

recipe += (“\r\n\r\nDIRECTIONS \r\n” + item.Directions);

request.Data.SetText(recipe);

//Share recipe image

var reference = RandomAccessStreamReference.CreateFromUri(newUri(item.ImagePath.AbsoluteUri));

request.Data.Properties.Thumbnail = reference;

request.Data.SetBitmap(reference);

}

  • Check the Sharing View with Windows stored applications :

  • Click on Share button from Windows Charm:

  • Select Mail to Share Applications Data & Image to text.

  • For Live Search Contract, lets create a SearchItemTemplate from Visual Studio 2012 templates.

  • Add  “ItemClick=”OnItemClick” on ListView named “resultsListView” & GridView named as “resultsGridView” of SearchItemPage.xaml.

//Search recipes and tabulate results

var groups = RecipeDataSource.GetGroups(“AllGroups”);

string query = queryText.ToLower();

var all = newList<RecipeDataItem>();

_results.Add(“All”, all);

foreach (var group in groups)

{

var items = newList<RecipeDataItem>();

_results.Add(group.Title, items);

foreach (var item in group.Items)

{

if (item.Title.ToLower().Contains(query) ||

item.Directions.ToLower().Contains(query))

{

all.Add(item);

items.Add(item);

}

}

filterList.Add(newFilter(group.Title, items.Count, false));

}

filterList[0].Count = all.Count;

}

private  void OnItemClick(object sender, ItemClickEventArgs e)

{

this.Frame.Navigate(typeof(ItemDetailPage),  ((RecipeDataItem)e.ClickedItem).UniqueId);

}

  • Lets check the Search Contract implementation from Windows Settings Charm by pressing Windows + C button.

Advertisements

About Anindita
Anindita Basak is working as Big Data Cloud Consultant in Microsoft. Worked in multiple MNCs as Developer & Senior Developer on Microsoft Azure, Data Platform, IoT & BI , Data Visualization, Data warehousing & ETL & of course in Hadoop platform.She played both as FTE & v- employee in Azure platform teams of Microsoft.Passionate about .NET , Java, Python & Data Science. She is also an active Big Data & Cloud Trainer & would love share her experience in IT Training Industry. She is an author, forum contributor, blogger & technical reviewer of various books on Big Data Hadoop, HDInsight, IoT & Data Science, SQL Server PDW & PowerBI.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: