Callisto Controls: Using Flyout in XAML

Flyout is a general purpose concept/control to give you a content control for the ‘popup’ behavior including light dismiss and positioning in accordance with Windows UI guidelines.

This control is likely primarily going to be used from some type of event handler from an AppBar button to accept input.  It is not meant to be a message dialog of any sorts.

Flyout with Input from Callisto

Thanks to Tim Heuer for developing this control.

As mentioned in the Flyout Wiki This control does not work declaratively i.e. via XAML. Well there is a simple way to do that. Here’s how:

1. Add a class called FlyoutHelper as below

[ContentProperty(Name = "FlyoutContent")]
public class FlyoutHelper : FrameworkElement
    {
Flyout flyout;

public FlyoutHelper()
        {
        }

public object PlacementTarget
        {
get { return (object)GetValue(PlacementTargetProperty); }
set { SetValue(PlacementTargetProperty, value); }
        }

// Using a DependencyProperty as the backing store for PlacementTarget.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty PlacementTargetProperty =
DependencyProperty.Register("PlacementTarget", typeof(object), typeof(FlyoutHelper), new PropertyMetadata(null));

public object FlyoutContent
        {
get { return (object)GetValue(FlyoutContentProperty); }
set { SetValue(FlyoutContentProperty, value); }
        }

// Using a DependencyProperty as the backing store for FlyoutContent.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty FlyoutContentProperty =
DependencyProperty.Register("FlyoutContent", typeof(object), typeof(FlyoutHelper), new PropertyMetadata(null));

        public void Show()
        {
if (flyout == null)
flyout = new Flyout();

flyout.PlacementTarget = (FrameworkElement)PlacementTarget;
            flyout.Content = FlyoutContent;

            flyout.IsOpen = true;
        }

        public void Hide()
        {
            flyout.IsOpen = false;

        }

public bool IsOpen { get { return flyout != null ? flyout.IsOpen : false; } }

    }

The main parts are the two methods Show and Hide which do the most work. I have added two properties which help me create the flyout. You can add more if at all you require them.

2. XAML Usage

Now you have to just place the control where you need it and setting up the target control. Like below:

<Controls:<span class="hiddenSpellError">FlyoutHelper  x:Name="menu" PlacementTarget="{Binding ElementName=targetButton}">
    <Border Background="{StaticResource ApplicationPageBackgroundThemeBrush}" BorderBrush="{StaticResource ButtonBorderThemeBrush}" BorderThickness="1"  Padding="5">
<HyperlinkButton  Content="Sample Button" Style="{StaticResource TextButtonStyle}" Grid.Column="1" Grid.Row="1"/>
    </Border>
</Controls:FlyoutHelper>


Hope this helps in using the Callisto Controls. I might add publish this on Nuget soon.

Callisto: What Is It?

Callisto is a library for use in Windows 8 XAML applications (aka Metro style apps).  The XAML framework in Windows.UI.Xaml is great, but has some functionality that isn’t provided in-the-box in a few controls and APIs.  Callisto provides added functionality on top of the XAML UI framework for Windows.

Related Links

Json.NET 5.0 with .NET 4.5, BigInteger, Read-Only Collections and more

New and Updated Libraries

In Json.NET 5.0 there are a bunch of library version changes:

  • Added .NET 4.5 library
  • Added portable library targeting .NET 4.5 + WP8 + Win8
  • Removed the Silverlight library.
  • Removed the Windows Phone library

Upgrading library versions allows Json.NET to support new .NET features such as dynamic and async across more platforms.

Read more about this new release here

Download Json.NET from CodePlex or install using  NuGet

NuGet

Related links

Windows 8 Store Apps: Class Library vs. Windows Runtime Component

When I saw the new project dialog for Windows Store Apps or Windows 8 Apps, I had a problem. What is the difference between a Class Library project vs. Windows Runtime Component project.

SNAGHTMLa50e07

Even the description within Visual Studio was not that clear:

Class Library

A project that creates a managed class library for Windows Store apps or Windows Runtime components.

Windows Runtime Component

A project for a Windows Runtime component that can be used by Windows Store apps, regardless of the programming languages in which the apps are written.

This was what I found on the web:

A Windows Runtime Component project is a DLL that can export WinRT types. This means this project produces a metadata file (.WINMD), that can be consumed by Windows 8 Store app projects (or other Windows Runtime Component projects) in any supported projection language, such as C++, C# and JavaScript.

A Class Library (Windows Store apps) project is a DLL that can be used by Windows Store apps written in .NET languages only. The critical difference – no metadata file is created, so this cannot be used with other languages, as there is no common ground.

After some Googling, I found that a Windows Runtime Component cannot be used at all times? This seems to be the more flexible choice.

The problem with a Windows Runtime Component is that every public type must be a WinRT type – that means it must be sealed, it can’t inherit from anything (unless it’s something in the Windows.UI.Xaml namespace, such as Control and UserControl). Public fields are not allowed, making declaration of dependency properties a little harder, by forcing a split between a private static field and a public static property.

So something like below is not possible:

public abstract class ObservableObject : INotifyPropertyChanged
    {
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged([CallerMemberName] string name = null)
        {
var pc = PropertyChanged;
            if (pc != null)
pc(this, new PropertyChangedEventArgs(name));
        }
    }

This is classic base class for MVVM support. This does not compile, because an abstract class cannot be exported. We can remove the “public” then this will compile – but will not be exported, so nothing outside this assembly would be able to use it. In a Class Library (Windows Store apps) project, this would compile fine and be usable from other like-assemblies.

What about a plain vanilla Class Library? That is not usable from a Windows Store app, because it uses the full .NET framework, and not just the subset allowed in WinRT. This is exactly what Class Library (Windows Store apps) ensures.

Conclusion

If you’re writing .NET code to be used by other .NET libraries/apps for Windows Store, Class Library (Windows Store apps) is a more flexible choice. If you want the library to be used by any WinRT-compliant language, Windows Runtime Component is your choice.

Related Links

Element not found on BackgroundExecutionManager.RequestAccessAsync()

If your building a Windows store app with live tiles, you may have face this issue:

Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))

If you have, this is an issue with breakpoints and the user already accepting the lock screen access.

If you had a breakpoint on a line of code ABOVE that call in a function it would break no matter what I did.

Options

Move the breakpoint below – all good. OR Remove the breakpoint altogether – all good.

I choose the latter. Its just more simple.

Related links

Learn to build Windows Store apps

Windows 8 User experience guidelines

Use this index to quickly find the user experience (UX) guidelines that can help you create a great Windows Store app.  If you haven’t already, you should start by reading Making great Windows Store apps and Planning Windows Store apps.

Click to download the guidelines

Learn to build Windows Store apps

Learn the basics of Windows Store app development from MSDN.  Make use of these resources to create beautiful apps on the Windows 8 platform.

Here’s what it has to offer:

Planning apps

Make the right decisions during the planning phase to ease development and maximize your app’s potential in the Windows Store.

Designing UX for apps

Discover the resources and design guidance you need to build beautiful apps with the look and feel of Windows 8.

Packaging apps

Learn how to use Visual Studio to prepare and package your app for the Windows Store.

Selling apps

Navigate the Windows Store with confidence and maximize your exposure to potential customers.

API reference

Explore comprehensive developer platform documentation, including Windows Runtime, Windows Library for JavaScript and schema references.

Concepts and architecture

Beyond the how – learn why the Windows Store app development platform works the way it does, and discover advanced techniques to enhance your apps.

Developing games

Learn to develop games as Windows Store apps, and learn more about DirectX and C++ for game development.

End-to-end apps

Complete guidance for critical scenarios to enhance your understanding of key concepts and jumpstart your development projects.

Resources for iOS developers

If you’re familiar with building iOS apps, these design and programming resources will help you get started building Windows Store apps.

VS2012, Windows Phone and the “Reference to a higher version” error

Reblogged from Musings of a PC:

Having installed Windows 8 Pro, Visual Studio 2012 Premium and the new Windows Phone 8 SDK, I was keen to make sure that my Windows Phone 7.1 project still built & worked. That meant getting all of the references to work again.

Most of the references were for packages that I could install through Nuget. However, one was for a Zip file that I had to download and unpack.

Read more… 92 more words

Thanks. I had the same problem for Microsoft.Practices.Prism.Interactivity.dll

Silverlight 5 Validation

Here is a post on Silverlight validation from Steven Hollidge on #WINNING with C#

Silverlight 5 Validation

Moving forward with .NET 4.5 the validation story will be played out through the INotifyDataErrorInfo interface.

http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.110).aspx

This demo can also be accessed online here.

Tricks

This example shows the following tricks when validating user input in Silverlight:

  • MVVM with independent validation rules allowing for contextual validation with injection into view model via the constructor
  • No validation is applied when first loading up the form
  • Validation is applied when each control is updated, with form wide validation being applied when the user clicks the Ok button
  • DatePicker control is loaded with no date and also prevents user textual input along with its validation
  • Fluent Validation uses length, email and regex rules to validate properties
  • View model implements INotifyPropertyChanged, INotifyDataErrorInfo and IEditableObject interfaces
  • INotifyPropertyChanged and INotifyDataErrorInfo implementations are stored within an abstract view model base class
  • Model implements bespoke generic ICloneable interface
  • Cancel (by pressing escape) on grid reverts the data and controls back to original state
  • RelayCommand has been used for the command buttons

Screenshots

Description viewer

Used to show if a field is required and/or any of other relevant info, when the user hovers over the little circle with the i for information to the right of the control.

image

Validation Summary

Lists all validation errors on the grid and form.

image

image

Validation Tooltips

image

image

Read more at #WINNING with C# – Silverlight 5 Validation

Updating Windows Phone 7 App to Windows Phone 8

Windows Phone 8 added exciting new features that you can make use in your app. I decided to upgrade my app Near Me to Windows Phone 8.

I had two choices going for the upgrade, migrate my app to Windows Phone 8 or maintain two separate versions of the app, one for Windows Phone 7.x and another for Windows Phone 8. I went ahead with the second option. To maintain both versions, I decided to use branching in source control. I use Team foundation service as my source control and wanted to leverage the branching capabilities. This way, I could merge any code from either version into the other version easily.

Post the branching, I selected the project in Visual Studio and said, “Upgrade to Windows Phone 8.0″. This was simple and my project was ready for Windows Phone 8. Well, almost.

I had referenced the Micrososft.Bcl.Async package via NuGet and this started giving problems along with the advertising SDK for Windows Phone. I then deleted both these references and added Windows Phone 8 versions of them.

Next stop was to start using Windows Phone 8 features. Here’s a list of changes that I had to do:

  1. Maps control
    Earlier I was using the Bing Maps control for showing the map, this had to be changed to Maps control in Windows Phone 8.
    Do make a note that the namespace declaration has also changed.
    xmlns
    :Microsoft_Phone_Controls_Maps=”clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps”
    to
    xmlns:maps=”clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps”
    Then you also have to get a Map service token from the dev center for your app which is different from the earlier process for Bing.
    Using the new control gives access to caching and offline access to maps as explained by The Windows Phone Map Control by Adam Denning 
  2. Geolocation
    There has been a new addition of the Geolocation class to retrieve the phone current location. This has been well documented in this post Updating your Windows Phone Location code to use WinRT  by Adam Denning. However the new GetGeopositionAsync method was giving problems to me, and I had to create a similar wrapper on this method using the event pattern. I’ll write about it in another post.
  3. ReverseGeocodeQuery
    Windows Phone 8 has now introduced a new API(s) which allow the facility for reverse geocoding without the need of any external services. Thanks, to this I removed the Bing service reference with Microsoft.Phone.Maps.Services.ReverseGeocodeQuery . This API provides more details like street and pincode along with city name whenever available.
  4. Tiles
    Adding support for live tiles was the last change that I did in my process of upgrading to windows phone 8. I selected the Flip Tile template for my app after going through the Tile design guidelines for Windows Phone 8.This is how my live tile looks like.
    MainTile
    Secondary-Tile
  5. I have added support for pining results to start screen using secondary tile as well.

There are few more accounts of upgrading to Windows Phone 8, here is Scott Hanselman‘s account on his blog.

Resources on MSDN

Tile design guidelines for Windows Phone 8

A Tile allows you to present rich and engaging content to your customers on the Windows Phone Start screen when your app isn’t running.

Windows Phone Tile overview image

Tile design philosophy

Your goal is to create an appealing Tile for your app. If you use a live Tile, your goal is to present engaging new content that your customers will find valuable to see in their Start screen and that invites them to launch the app. To that end, avoid the overuse of loud colors. Simple, clean, elegantly designed tiles will be more successful than those that scream for attention.

When you’re designing your app, consider using a live Tile for several reasons:

  • Tiles are the “front door” to your app. A compelling live Tile can draw users into your app when your app isn’t running. Customers increasingly value an app that they use frequently.
  • A live Tile is a selling point that differentiates your app from apps on operating systems that only allow static Tiles and icons in their Start screen.
  • A live Tile is a selling point that differentiates your app from other apps in the Windows Phone Store. Customers are likely to prefer the app with the great live Tile to a similar app with a static tile.
  • If customers like your live Tile, a prominent placement of that Tile in Start will drive reengagement with your app. Serendipitous discovery of cool content in the app through the tile will make users happy.
  • If users don’t like your Tile, they might place it at the end of Start or unpin it altogether, turn off updates, or even uninstall your app.

Some characteristics that make a live Tile compelling are:

  • Fresh, frequently updated content that makes customers feel that your app is active even when it’s not running.Example: Showing the latest headlines or a count of new e-mails.
  • Personalized or tailored updates that use what you know about your customer, such as interests that you allow the customer to specify through app settings.Example: Deals of the day tailored to the customer’s hobbies.
  • Content relevant to the customer’s current context.Example: A traffic condition app that uses the customer’s current location to display a relevant traffic map.

Tile templates

Windows Phone 8 supports three Tile templates: flip, iconic, and cycle. It’s important to carefully choose a template for your default Tile

The template type you should choose depends on the type of app you build and the design you’re going for. For more information about how to choose the right Tile template, see Choosing the best Tile template for your app for Windows Phone.

Flip template

The Tile flips from front to back. This template might look familiar to Windows Phone OS 7.1 developers, because the template is based on the Windows Phone OS 7.1 Tile template. For more information about this template, see Flip Tile template for Windows Phone 8.

Windows Phone Flip Tile template showcase image

Iconic template

The Tile is based on Windows Phone design principles. For more information about this template, see Iconic Tile template for Windows Phone 8.

Windows Phone Iconic Tile template showcase image

Cycle template

The Tile cycles through up to nine images. For more information about this template, see Cycle Tile template for Windows Phone 8.

Windows Phone Cycle Tile template showcase image

Related Links

Runaway tasks in Windows Phone Applications

The task parallel library is one of the good additions to Windows Phone development. However, using the Task Parallel Library within the Windows Phone application can become tricky.

While developing an app, I found that when you await on a Tasks say a Web client download in the Loaded event of a page. Now when the users moves out of the page to another one, the Web client call can complete in the background. Since you were awaiting on this background call, the code after the await may proceed, resulting in an un-expected scenario.

This was the same problem I face in my app. I was loading some data on the loaded event of a page in my app. When the data load call failed due to whatever reason , I displayed a popup saying “Sorry, We could not find any data for you”. Now when I navigated to this page and quickly navigated back multiple times, many data calls were made.

Now assuming all the calls failed one after another, the user was shown these annoying popups out of the blue.

The bottom line, when using tasks to download data, make sure that you terminate such calls when a user navigates away from the page.

I might post some additional details and my final resolution to the problem later.

Hope this helps.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: