Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Managing Multiple selection in View Model (.NET Metro Style Apps)

, 29 Jun 2012 CPOL
This article provides Attached Behavior based approach to manage Multiple Selection in Collection Based UI control from the View Model. All the code in this article is strictly applicable to Win 8 metro style apps. Though the Behaviors can be easily adapted to WPF/Silverlight.
Multiselect_in_VM.zip
Multiselect in VM
~$ltiselect Binding in ViewModel-Metro.docx
~$w Microsoft Word Document.docx
Ext
winrtbehaviors-14177.zip
winrtbehaviors-14177
Multiselect Binding in ViewModel-Metro.docx
MultiselectSample
depend
GalaSoft.MvvmLight.Win8.dll
WinRtBehaviors.dll
MultiselectSample
Assets
Logo.png
SmallLogo.png
SplashScreen.png
StoreLogo.png
bin
Debug
AppX
Assets
Logo.png
SmallLogo.png
SplashScreen.png
StoreLogo.png
Common
GalaSoft.MvvmLight.Win8.dll
microsoft.system.package.metadata
S-1-5-21-860198490-3370951563-2996008965-1001.pckgdep
MultiselectSample.exe
resources.pri
vs.appxrecipe
WinRtBehaviors.dll
WinRtExt.dll
Common
GalaSoft.MvvmLight.Win8.dll
MultiselectSample.build.appxrecipe
MultiselectSample.exe
resources.pri
WinRtBehaviors.dll
WinRtExt.dll
WinRtExt.pri
Common
MultiselectSample_TemporaryKey.pfx
obj
Debug
Common
intermediatexaml
TempPE
Package.appxmanifest
Properties
WinRtBehaviors
bin
Debug
WinRtBehaviors.dll
WinRtBehaviors.pri
obj
Debug
TempPE
Properties
WinRtBehaviors.csproj.vspscc
WinRtBehaviors.vssscc
WinRtExt
Behavior
bin
ARM
Debug
Release
Debug
WinRtBehaviors.dll
WinRtBehaviors.pri
WinRtExt.dll
WinRtExt.pri
Release
x64
Debug
Release
x86
Debug
Release
obj
Debug
TempPE
Properties
ori
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
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;

// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227

namespace MultiselectSample
{
    /// <summary>
    /// Provides application-specific behavior to supplement the default Application class.
    /// </summary>
    sealed partial class App : Application
    {
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
        }

        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            // Do not repeat app initialization when already running, just ensure that
            // the window is active
            if (args.PreviousExecutionState == ApplicationExecutionState.Running)
            {
                Window.Current.Activate();
                return;
            }

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            // Create a Frame to act navigation context and navigate to the first page
            var rootFrame = new Frame();
            if (!rootFrame.Navigate(typeof(MainPage)))
            {
                throw new Exception("Failed to create initial page");
            }

            // Place the frame in the current Window and ensure that it is active
            Window.Current.Content = rootFrame;
            Window.Current.Activate();
        }

        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            //TODO: Save application state and stop any background activity
            deferral.Complete();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Fun@learn
Software Developer (Senior)
India India
Software Engineer based out in Noida.

Technology skillset – .NET, WPF, WCF, LINQ, XAML.

Started blogging on http://1wpf.wordpress.com/


Stackoverflow Profile -> http://stackoverflow.com/users/649524/tilak

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 29 Jun 2012
Article Copyright 2012 by Fun@learn
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid