Git Product home page Git Product logo

boxkite.notifications's Introduction

BoxKite.Notifications

What is this?

Create notifications for your Windows 8 apps without parsing XML like a caveman.

I can't take credit for the initial code - it came from a Windows 8 MSDN sample.

So rather than copy the source code into each app, I've pulled this out to a NuGet package so that it is easier to consume (for me and for everyone else). I'm also cleaning up the code for readability as I go.

To install it from NuGet:

###PM> Install-Package BoxKite.Notifications -Version 0.0.4-pre -Pre

How do I use it?

First off, have a look at the notification templates available for creating notifications. This will give you an idea of what information you can show to users.

After installing the NuGet package, add these namespaces to the top of the class:

using BoxKite.Notifications;
using BoxKite.Notifications.Templates;

Tile Notifications

Then, use the TileContentFactory static class to create the desired template and populate the content.

var tileUpdate = TileContentFactory.CreateTileWideSmallImageAndText03();
tileUpdate.Image.Src = tweet.User.Avatar;
tileUpdate.TextBodyWrap.Text = tweet.Text;
tileUpdate.Image.Alt = tweet.User.Name;

var squareUpdate = TileContentFactory.CreateTileSquareText04();
squareUpdate.TextBodyWrap.Text = tweet.Text;
tileUpdate.SquareContent = squareContent;

Note: why did I create two tiles? Because the live tiles may be wide or square depending on how the user has configured the tile - don't forget this!

And lastly, send this update to the TileUpdateManager:

TileUpdateManager.CreateTileUpdaterForApplication().Update(tileUpdate.CreateNotification()); 

And that's it. How easy is that?

Toast Notifications

These behave in a similar way, using ToastContentFactory instead.

var notifier = ToastNotificationManager.CreateToastNotifier();
if (notifier.Setting == NotificationSetting.Enabled)
{
    var template = ToastContentFactory.CreateToastImageAndText04();

    template.TextHeading.Text = "Some Heading";
    template.TextBody1.Text = "Words go here";
    template.TextBody2.Text = "and also here";
    template.Image.Src = "https://dl.dropbox.com/u/5803705/sample.png";

    ToastNotificationManager.CreateToastNotifier().Show(template.CreateNotification());    
}

What else is missing?

I haven't integrated the BadgeContent samples (to show numbers or symbols on the tile). Let's see if I can do this now

I'd rather keep this library specialized for a single task, but if there's features you think would work nicely within this context you can get in touch on Twitter or leave an issue on the site...

Also open to pull requests to simplify the API - while the syntax makes it easy to discover, I'm not a huge fan of the template.Foo.Bar.Something dot-heavy conventions...

Why MS-LPL (Microsoft Limited Public License)?

Personally, I would have chosen a more permissive license. However this was the licence associated with all the Windows 8 samples. I am not a lawyer, so I am choosing to follow the upstream licenses with this project.

boxkite.notifications's People

Contributors

shiftbot avatar vikingcode avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.