Using the LibraryStack Control

The LibraryStack control that is included in the Microsoft Surface Toolkit for Windows Touch Beta is an ItemsControl object that enables you to display items that are stacked on each other. Users can view the individual items by rearranging the order of the stack or by removing items from the stack. By default, the LibraryStack control supports drag-and-drop operations. See Using Drag-and-Drop with the LibraryBar and LibraryStack Controls for more information.

LibraryStack - Close-up example

In the following code example, a LibraryStack control is created as part of a SurfaceWindow object. The DataTemplate for the LibraryStack control is set to show the images that are bound to the control.


        <s:LibraryStack Name="MainLibraryStack">
                    <Image Source="{Binding}"/>

In the code for SurfaceWindow, the OnInitialized method is overridden to set the ItemsSource property of the LibraryStack control to a collection of sample images.

protected override void OnInitialized(EventArgs e)

    // Query the registry to find out where the sample photos are stored.
    const string shellKey =
        @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Folders";

    string imagesPath =
        (string)Microsoft.Win32.Registry.GetValue(shellKey, "CommonPictures", null) + @"\Sample Pictures";

        // Get the list of files.
        string[] files = System.IO.Directory.GetFiles(imagesPath, "*.jpg");

        // Create an ObservableCollection from the file names.
        // Cannot assign string[] files to LibraryStack.ItemsSource.
        // LibraryStack.ItemsSource must implement INotifyCollectionChanged.
        ObservableCollection<string> items = new ObservableCollection<string>(files);

        // Set the ItemsSource property.
        MainLibraryStack.ItemsSource = items;
    catch (System.IO.DirectoryNotFoundException)
        // Handle exception as needed.

See Also

Community Additions