Click here to Skip to main content
15,884,388 members
Articles / Desktop Programming / WPF

DataObjectBase

Rate me:
Please Sign up or sign in to vote.
4.66/5 (20 votes)
18 May 2010CPOL8 min read 37.7K   572   59  
DataObjectBase -> the new Object class for data objects!
using System.Windows;
using System.Windows.Input;
using CatenaLogic.Examples.Data;
using CatenaLogic.Examples.UI.Input;
using CatenaLogic.Windows;

namespace CatenaLogic.Examples.UI.Windows
{
    /// <summary>
    /// Interaction logic for RevertAndApplyWindow.xaml
    /// </summary>
    public partial class RevertAndApplyWindow : DataWindow
    {
        #region Variable
        private bool _hasState = false;
        #endregion

        #region Constructor & destructor
        /// <summary>
        /// Initializes a new instance of the <see cref="RevertAndApplyWindow"/> class.
        /// </summary>
        public RevertAndApplyWindow()
            : base(DataWindowMode.Close)
        {
            // Initialize component
            InitializeComponent();

            // Add command bindings
            CommandBindings.Add(new CommandBinding(RevertAndApplyCommands.CreateState, CreateState_Executed, CreateState_CanExecute));
            CommandBindings.Add(new CommandBinding(RevertAndApplyCommands.Revert, Revert_Executed, Revert_CanExecute));
            CommandBindings.Add(new CommandBinding(RevertAndApplyCommands.Apply, Apply_Executed, Apply_CanExecute));
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets RevertAndApplyObject.
        /// </summary>
        /// <remarks>
        /// Wrapper for the RevertAndApplyObject dependency property.
        /// </remarks>
        public RevertAndApplyObject RevertAndApplyObject
        {
            get { return (RevertAndApplyObject)GetValue(RevertAndApplyObjectProperty); }
            set { SetValue(RevertAndApplyObjectProperty, value); }
        }

        /// <summary>
        /// DependencyProperty definition as the backing store for RevertAndApplyObject.
        /// </summary>
        public static readonly DependencyProperty RevertAndApplyObjectProperty =
            DependencyProperty.Register("RevertAndApplyObject", typeof(RevertAndApplyObject), typeof(RevertAndApplyWindow), new UIPropertyMetadata(new RevertAndApplyObject()));

        #endregion

        #region Command bindings
        /// <summary>
        /// Determines whether the user can execute the CreateState command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">The event data.</param>
        private void CreateState_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            // Only allow when there is no state
            e.CanExecute = !_hasState;
        }

        /// <summary>
        /// Handled when the user invokes the CreateState command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Arguments.</param>
        private void CreateState_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Create state
            RevertAndApplyObject.BeginEdit();

            // State
            _hasState = true;
        }

        /// <summary>
        /// Determines whether the user can execute the Revert command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">The event data.</param>
        private void Revert_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            // Only allow when there is a state
            e.CanExecute = _hasState;
        }

        /// <summary>
        /// Handled when the user invokes the Revert command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Arguments.</param>
        private void Revert_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Cancel edit
            RevertAndApplyObject.CancelEdit();

            // No state
            _hasState = false;
        }

        /// <summary>
        /// Determines whether the user can execute the Apply command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">The event data.</param>
        private void Apply_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            // Only allow when there is a state
            e.CanExecute = _hasState;
        }

        /// <summary>
        /// Handled when the user invokes the Apply command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Arguments.</param>
        private void Apply_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // End edit
            RevertAndApplyObject.EndEdit();

            // No state
            _hasState = false;
        }
        #endregion

        #region Methods
        #endregion
    }
}

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
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions