public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            try
            {
                if (value == null)
                {
                    return(new ValidationResult(false, "You must enter a non-empty value"));
                }


                if (value is BindingGroup) //Since our XAML has ValidationStep="UpdatedValue" />, then our value is now of type BindingExpression, not the normal string that we expected.
                {
                    BindingGroup bg = value as BindingGroup;
                    //CiresonTimerActivity ta = bg.Owner.
                    StackPanel sp = bg.Owner as StackPanel;
                    CiresonTimerActivityViewModel taViewModel = sp.DataContext as CiresonTimerActivityViewModel;
                    string strError = null;
                    if (taViewModel.HasValidDateInfoEntered(out strError))
                    {
                        return(ValidationResult.ValidResult);
                    }
                    else
                    {
                        return(new ValidationResult(false, strError));
                    }
                }


                return(new ValidationResult(false, "Was not expecting this obejct here..."));
            }
            catch
            {
                return(new ValidationResult(false, "You must make a selection and enter a value"));
            }
        }
        public void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            //Our datacontext likes to change after the form has been loaded. Refresh some stuff.
            Console.WriteLine("UserControl_DataContextChanged"); //TODO: delete me.

            if (this.DataContext == null)
            {
                return;
            }

            if (this.DataContext is IDataItem == false && this.DataContext is EnterpriseManagementObject == false && this.DataContext is EnterpriseManagementObjectProjection == false)
            {
                return;
            }

            this.IsEnabled = false;

            //SCSM will eventually load the DataContext as an IDataItem. This can't really be changed, since SCSM requires an IDataItem when pressing the OK or Apply buttons.
            //Set the dataitem from the DataContext

            if (this.DataContext is IDataItem)
            {
                var idataItem = this.DataContext as IDataItem;

                //If this is a new item, then double check and make sure that our workitem ID has a prefix.
                if ((bool)idataItem["$IsNew$"] == true)
                {
                    var strPrefix = Microsoft.EnterpriseManagement.UI.Extensions.Shared.ConsoleContextHelper.Instance.GetActivityPrefix(idataItem);
                    if (strPrefix != null && strPrefix.Length > 0 && idataItem["Id"].ToString().StartsWith(strPrefix) == false)
                    {
                        //it's a brand new WI? Add hte prefix.
                        idataItem["Id"] = strPrefix + idataItem["Id"];
                    }
                }

                //Merge this form with the instance, using our full type projection
                //ConsoleContextHelper.Instance.FetchAndMergeSubProjection(idataItem, guid_notificationActivityFullProjection); //Obsolete
                Microsoft.EnterpriseManagement.UI.Extensions.Shared.ConsoleContextHelper.Instance.FetchAndMergeSubProjection(idataItem, Constants.guid_Projection_CiresonTimerActivity_FullProjection);



                //We also have to load our viewmodel with other properties.
                activityViewModel = new CiresonTimerActivityViewModel(idataItem, IsTemplateMode());

                paneltestconfirmation.Visibility = Visibility.Hidden;
            }
            else if (this.DataContext is EnterpriseManagementObject)
            {
                var emoActivity = this.DataContext as EnterpriseManagementObject;                     //Set this globally here.

                activityViewModel = new CiresonTimerActivityViewModel(emoActivity, IsTemplateMode()); //Also set this globally here.

                paneltestconfirmation.Visibility = Visibility.Visible;
            }
            else if (this.DataContext is EnterpriseManagementObjectProjection)
            {
                throw new NotImplementedException("Code for EnterpriseManagementObject Projection not implemented yet");
            }


            //Update the datacontext with our new viewmodel, but in a different thread.
            Task.Factory.StartNew(UpdateDataContextFromViewModel);  //UpdateViewModelFromScsmObject(naViewModel); //Calling this here without a task would not be from a different thread, and we would see no change.
            //this.DataContext = naViewModel; //Removes the iDataItem or EMO or EMOP and replaces it with our viewModel. Doesn't work within this method.
        }