Esempio n. 1
0
        private void CloseAndSaveResults(object sender, RoutedEventArgs e)
        {
            //if we received a list of controls to save, we will
            if (ControlsToSave != null && ControlsToSave.Length > 0)
            {
                //scrape the Controls from the ControlsToSave name array
                List <FrameworkElement> controlsToParseForOutput = FormsCreator.FindChildren(StackPanel, ControlsToSave);
                Results = FormsCreator.GetDataFromWPFWindow(controlsToParseForOutput.ToArray(), SaveEverything, null);
            }
            else
            {
                //scrape the values provided for us in the Inputs table

                string[] elementNames;
                //get the element names from the input dictionary
                elementNames = Inputs.Select(x => x.Key).ToArray();
                List <FrameworkElement> controlsToParseForOutput = FormsCreator.FindChildren(StackPanel, elementNames);
                //scrape results
                Results = FormsCreator.GetDataFromWPFWindow(controlsToParseForOutput.ToArray(), SaveEverything, Inputs);
            }


            //close window
            Window.GetWindow(this).Close();
        }
        public static Dictionary <string, Dictionary <string, object> > GetDataFromWPFWindow(
            FrameworkElement[] controlsToParseForOutput,
            bool getAllData = false,
            Dictionary <string, Dictionary <string, object> > Inputs = null)
        {
            Dictionary <string, Dictionary <string, object> > Results = new Dictionary <string, Dictionary <string, object> >();

            //loop through the Elements in the dictionary
            foreach (FrameworkElement currentFrameworkElement in controlsToParseForOutput)
            {
                if (!getAllData)
                {
                    //get the properties mapped in the Input Dictionary for the current Control
                    KeyValuePair <string, Dictionary <string, object> > elementValuesPair = Inputs.Where(x => x.Key == currentFrameworkElement.Name).FirstOrDefault();
                    Dictionary <string, object> resultsForControl = FormsCreator.GetPropertiesFromControl(currentFrameworkElement, elementValuesPair.Value);
                    Results.Add(elementValuesPair.Key, resultsForControl);
                }
                else
                {
                    //get all non-null properties from the Control
                    Dictionary <string, object> resultsForControl = FormsCreator.GetAllPropertiesFromControl(currentFrameworkElement);
                    Results.Add(currentFrameworkElement.Name, resultsForControl);
                }
            }

            return(Results);
        }
        /// <summary>
        /// gets a named property of a WPF control
        /// </summary>
        public static Dictionary <string, object> GetPropertiesFromControl(FrameworkElement currentFrameworkElement, Dictionary <string, object> propertiesToGet)
        {
            //loop through all properties in the input dictionary and create an output dictionary
            Dictionary <string, object> resultsForControl = new Dictionary <string, object>();

            foreach (KeyValuePair <string, object> nameValuePair in propertiesToGet)
            {
                //get value and add it to the dictionary
                object valueObtained = FormsCreator.GetValueForProperty(currentFrameworkElement, nameValuePair.Key);
                resultsForControl.Add(nameValuePair.Key, valueObtained);
            }

            return(resultsForControl);
        }
Esempio n. 4
0
        private void SetInitializationValues(Dictionary <string, Dictionary <string, object> > initializationValues)
        {
            //loop through the Elements in the dictionary
            foreach (KeyValuePair <string, Dictionary <string, object> > elementValuesPair in initializationValues)
            {
                //get element from DOM
                MethodInfo method = typeof(FormsCreator).GetMethod("FindChild");
                dynamic    result = method.Invoke(this, new object[] { StackPanel, elementValuesPair.Key });
                if (result == null)
                {
                    throw new Exception("WPF control with name: " + elementValuesPair.Key + " was not found. Check the input dictionary Values");
                }

                //set all properties for the current control
                foreach (KeyValuePair <string, object> nameValuePair in elementValuesPair.Value)
                {
                    FormsCreator.SetValueForProperty(result, nameValuePair.Key, nameValuePair.Value);
                }
            }
        }