public RegisterMethodModel GetControlValues()
        {
            RegisterMethodModel registerMethodModel = new RegisterMethodModel();

            registerMethodModel.SelectedOverload = (RegisterMethodOverload)cBRegisterMethodOverload.SelectedValue;
            registerMethodModel.NameOfProperty   = tBNameOfTheProperty.Text;
            registerMethodModel.TypeOfProperty   = tBTypeOfTheProperty.Text;
            registerMethodModel.OwnerOfProperty  = tBOwnerOfTheProperty.Text;

            return(registerMethodModel);
        }
Пример #2
0
        private void GenerateDPBasic(RegisterMethodModel registerMethodModel)
        {
            //Step 1 -> Dependency property
            StringBuilder declarationDependencyProperty = new StringBuilder();

            declarationDependencyProperty.AppendLine("public static readonly DependencyProperty " + registerMethodModel.NameOfProperty + "Property;\n\n");

            //Step 2 -> Register DP
            StringBuilder registerDependencyProperty = new StringBuilder();

            registerDependencyProperty.Append("static " + registerMethodModel.OwnerOfProperty + "()\n{\n\t" + registerMethodModel.OwnerOfProperty + "." + registerMethodModel.NameOfProperty + "Property = DependencyProperty.Register(" + "\"" + registerMethodModel.NameOfProperty + "\", " + "typeof(" + registerMethodModel.TypeOfProperty + "), " + "typeof(" + registerMethodModel.OwnerOfProperty + "));\n}\n\n");

            //Step 3 -> Wrapper
            StringBuilder wrapperDependencyProperty = new StringBuilder();

            wrapperDependencyProperty.Append("public " + registerMethodModel.TypeOfProperty + " " + registerMethodModel.NameOfProperty + "\n{\n\t" + "get { return (" + registerMethodModel.TypeOfProperty + ")GetValue(" + registerMethodModel.OwnerOfProperty + "." + registerMethodModel.NameOfProperty + "Property);}\n\t" + "set { SetValue(" + registerMethodModel.OwnerOfProperty + "." + registerMethodModel.NameOfProperty + "Property, value); }\n}\n\n");

            tBDependencyProperty.Text = declarationDependencyProperty.ToString() + registerDependencyProperty.ToString() + wrapperDependencyProperty.ToString();
        }
Пример #3
0
        private void GenerateDPPropertyMetadata(RegisterMethodModel registerMethodModel, FrameworkPropertyMetadataModel frameworkPropertyMetadataModel)
        {
            #region Prepare FrameworkPropertyMetadata

            StringBuilder frameworkPropertyMetadata = new StringBuilder();

            FrameworkPropertyMetadataOverload selectedFrameworkOverload = frameworkPropertyMetadataModel.SelectedOverload;
            string _frameworkPropertyMetadataOptionsText = getMetadataOptions(frameworkPropertyMetadataModel.FrameworkPropertyMetadataOptions);
            string separator = ", ";

            switch (selectedFrameworkOverload)
            {
            case FrameworkPropertyMetadataOverload.Basic:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata()");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValue:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + ")");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValueMetadataOption:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + separator + _frameworkPropertyMetadataOptionsText + ")");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValueMetadataOptionPropertyChanged:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + separator + _frameworkPropertyMetadataOptionsText + separator + "new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + "))");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValueMetadataOptionPropertyChangedCoerce:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + separator + _frameworkPropertyMetadataOptionsText + separator + "new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + ")" + separator + "new CoerceValueCallback(" + frameworkPropertyMetadataModel.CoerceValueCallbackName + "))");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValueMetadataOptionPropertyChangedCoerceAnimation:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + separator + _frameworkPropertyMetadataOptionsText + separator + "new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + ")" + separator + "new CoerceValueCallback(" + frameworkPropertyMetadataModel.CoerceValueCallbackName + ")" + separator + frameworkPropertyMetadataModel.Animation + ")");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValueMetadataOptionPropertyChangedCoerceAnimationUpdateTrigger:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + separator + _frameworkPropertyMetadataOptionsText + separator + "new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + ")" + separator + "new CoerceValueCallback(" + frameworkPropertyMetadataModel.CoerceValueCallbackName + ")" + separator + frameworkPropertyMetadataModel.Animation + separator + "UpdateSourceTrigger." + frameworkPropertyMetadataModel.UpdateSourceTriggerName + ")");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValuePropertyChanged:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + separator + "new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + "))");

                break;

            case FrameworkPropertyMetadataOverload.DefaultValuePropertyChangedCoerce:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(" + frameworkPropertyMetadataModel.DefaultValue + separator + "new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + ")" + separator + "new CoerceValueCallback(" + frameworkPropertyMetadataModel.CoerceValueCallbackName + "))");

                break;

            case FrameworkPropertyMetadataOverload.PropertyChanged:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + "))");

                break;

            case FrameworkPropertyMetadataOverload.PropertyChangedCoerce:

                frameworkPropertyMetadata.Append("FrameworkPropertyMetadata(new PropertyChangedCallback(" + frameworkPropertyMetadataModel.PropertyChangedCallbackName + ")" + separator + "new CoerceValueCallback(" + frameworkPropertyMetadataModel.CoerceValueCallbackName + "))");

                break;
            }

            #endregion

            //Step 1 -> Dependency property
            StringBuilder declarationDependencyProperty = new StringBuilder();
            declarationDependencyProperty.AppendLine("public static readonly DependencyProperty " + registerMethodModel.NameOfProperty + "Property;\n\n");

            //Step 2 -> Register DP
            StringBuilder registerDependencyProperty = new StringBuilder();
            registerDependencyProperty.Append("static " + registerMethodModel.OwnerOfProperty + "()\n{\n\t" + registerMethodModel.OwnerOfProperty + "." + registerMethodModel.NameOfProperty + "Property = DependencyProperty.Register(" + "\"" + registerMethodModel.NameOfProperty + "\", " + "typeof(" + registerMethodModel.TypeOfProperty + "), " + "typeof(" + registerMethodModel.OwnerOfProperty + "),\n\t" + frameworkPropertyMetadata + ");\n}\n\n");

            //Step 3 -> Wrapper
            StringBuilder wrapperDependencyProperty = new StringBuilder();
            wrapperDependencyProperty.Append("public " + registerMethodModel.TypeOfProperty + " " + registerMethodModel.NameOfProperty + "\n{\n\t" + "get { return (" + registerMethodModel.TypeOfProperty + ")GetValue(" + registerMethodModel.OwnerOfProperty + "." + registerMethodModel.NameOfProperty + "Property);}\n\t" + "set { SetValue(" + registerMethodModel.OwnerOfProperty + "." + registerMethodModel.NameOfProperty + "Property, value); }\n}\n\n");


            //Step 4 - > Callbacks
            StringBuilder dependencyPropertyCallbacks = new StringBuilder();
            if (!string.IsNullOrEmpty(frameworkPropertyMetadataModel.PropertyChangedCallbackName))
            {
                dependencyPropertyCallbacks.Append("private static void " + frameworkPropertyMetadataModel.PropertyChangedCallbackName + "(DependencyObject o, DependencyPropertyChangedEventArgs e)\n{\n\n}\n\n");
            }

            if (!string.IsNullOrEmpty(frameworkPropertyMetadataModel.CoerceValueCallbackName))
            {
                dependencyPropertyCallbacks.Append("private static void " + frameworkPropertyMetadataModel.CoerceValueCallbackName + "(DependencyObject d, object value)\n{\n\n}\n\n");
            }

            tBDependencyProperty.Text = declarationDependencyProperty.ToString() + registerDependencyProperty.ToString() + wrapperDependencyProperty.ToString() + dependencyPropertyCallbacks.ToString();
        }