Differences between revisions 1 and 2
Revision 1 as of 2012-09-18 22:32:59
Size: 1110
Editor: 24-151-197-61
Comment:
Revision 2 as of 2012-09-18 22:33:27
Size: 1112
Editor: 24-151-197-61
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
{{{#!csharp {{{
#!csharp

Chat Server and WPF Client

Client

For the client code I used WPF and the MVVM pattern. From the bottom up the first thing I used is a DelegateCommand

using System;
using System.Windows.Input;

namespace ChatClient
{
    class DelegateCommand : ICommand
    {
        private readonly Predicate<object> _canExecute;
        private readonly Action<object> _execute;

        public event EventHandler CanExecuteChanged;

        public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
        {
            _execute = execute;
            _canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            return _canExecute == null || _canExecute(parameter);
        }

        public void Execute(object parameter)
        {
            _execute(parameter);
        }

        public void RaiseCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, EventArgs.Empty);
            }
        }
    }
}

PrinciplesOfNetworkingCourse/Programs/ChatExample (last edited 2016-09-06 23:10:53 by 71-88-174-29)