Click here to Skip to main content
15,886,798 members
Articles / Desktop Programming / WPF

Executing Command Logic in a View Model

Rate me:
Please Sign up or sign in to vote.
4.94/5 (54 votes)
9 Mar 2011CPOL14 min read 304.3K   2.8K   142  
Introduces the RoutedCommandBinding class as a new way for invoking methods in a View Model directly from XAML in an MVVM application.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

namespace RoutedCommandBindingSample
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var mainWindow = new MainWindow();
            var player = new SimpleMediaPlayer();
            player.SourceUri = "http://www.pure.fm/prog.m3u";
            mainWindow.DataContext = player;
            mainWindow.Show();
        }
    }
}

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)


Written By
Software Developer Fidelity National Financial
United States United States
Doug Schott has been developing .NET applications for the past 8 years.

He is currently working as a senior software consultant at Fidelity National Financial.

Comments and Discussions