private void PublishResponseSetFocus(XElement publishElt)
        {
            if (publishElt.Attribute(Common.focusField) != null)
            {
                string field = publishElt.Attribute(Common.focusField).Value;

                if (FixedContext != null)
                {
                    if (field.StartsWith(FixedContext))
                    {
                        field = field.Remove(0, FixedContext.Length + 1);
                    }
                }

                if (Controls.Count(x => x.FieldId == field) != 0)
                {
                    var control = Controls.First(x => x.FieldId == field) as Control;

                    if (control != null)
                    {
                        control.Focus();
                    }
                }
                else if (DataControls.ContainsKey(field))
                {
                    var control = DataControls[field] as Control;

                    if (control != null)
                    {
                        control.Focus();
                    }
                }
            }
        }
        /// <summary>
        /// This is kind of a hack to work around the issue in Silverlight where you don't know when
        /// all the controls have been loaded in a page (so you can *then* make a call to the server).
        /// All the XAML pages are parsed when the application is loaded to extract the expanz controls,
        /// and here we'll register them *before* they are actually loaded so that requests can be made
        /// to the server, and then these entries will be updated with the actual control references
        /// when the controls are actually loaded.
        /// </summary>
        internal void RegisterUnloadedControls(List <ExpanzControlDetails> expanzControls)
        {
            var controlsToRegister = expanzControls.Where(x => x.IsDataControl);

            foreach (ExpanzControlDetails controlDetails in controlsToRegister)
            {
                if (controlDetails.DataId != null && !DataControls.ContainsKey(controlDetails.DataId))
                {
                    DataControls.Add(controlDetails.DataId, controlDetails); // Add temporary dummy entry
                }
            }

            controlsToRegister = expanzControls.Where(x => x.IsMediaControl);

            foreach (ExpanzControlDetails controlDetails in controlsToRegister)
            {
                if (controlDetails.DataId != null && !DataControls.ContainsKey(controlDetails.DataId))
                {
                    MediaControls.Add(controlDetails.DataId, controlDetails); // Add temporary dummy entry
                }
            }
        }
        private void PublishResponseDataNodes(XElement publishElt)
        {
            IEnumerable <XElement> DataNodes = publishElt.Elements(Common.Data.Node);
            IEnumerator            ie        = DataNodes.GetEnumerator();

            while (ie.MoveNext())
            {
                try
                {
                    XElement data = (XElement)ie.Current;
                    string   id   = string.Empty;

                    if (data.Attribute(Common.IDAttrib) != null)
                    {
                        id = data.Attribute(Common.IDAttrib).Value;
                    }

                    if (id == Common.Picklist)
                    {
                        #if WPF
                        var PL = new PickListWindow(this, data);
                        PL.ShowDialog();
                        #endif
                    }
                    else
                    {
                        bool process = true;

                        if (FixedContext != null)
                        {
                            if (id.StartsWith(FixedContext))
                            {
                                id = id.Remove(0, FixedContext.Length + 1);
                            }
                        }

                        if (process)
                        {
                            if (DataControls.ContainsKey(id))
                            {
                                if (DataControls[id] is ExpanzControlDetails)
                                {
                                    // Control has not registered itself with the activity yet. Cache the data for when it does.
                                    _controlDataCache[id] = data;
                                }
                                else
                                {
                                    // Sometimes data controls need to know the field info both before and after
                                    // it has been fed the data. Therefore, find the corresponding field info
                                    // (if a field ID has been assigned), and pass that field info to the control
                                    // to process before the data is published to it.
                                    if (DataControls[id].FieldId != null)
                                    {
                                        // Find the corresponding field information for this control
                                        XElement fieldElement = publishElt.Elements(Common.FieldNode).Where(x => x.Attribute(Common.IDAttrib).Value == DataControls[id].FieldId).FirstOrDefault();

                                        if (fieldElement != null)
                                        {
                                            DataControls[id].PreDataPublishXml(fieldElement);
                                        }
                                    }


                                    DataControls[id].PublishData(data);
                                }
                            }
                            //else if (this.container is ViewModelBase)
                            //{
                            //    var vm = this.container as ViewModelBase;
                            //    vm.PublishData(data);
                            //}
                        }
                    }
                }
                catch (Exception e)
                {
                    Logging.LogException(e);
                }
            }
        }