Click here to Skip to main content
15,892,059 members
Articles / Desktop Programming / WPF

WPF Form Designer Prototype (MVVM)

Rate me:
Please Sign up or sign in to vote.
4.83/5 (31 votes)
3 Apr 2013CPOL9 min read 79.6K   3.4K   108  
Form designer with editable display properties and bindings. Generates XAML forms.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace WPFFormDesigner.WPFPropertyGridProxies
{
    public static class ControlBindingExtensions
    {
        public static DependencyProperty GetDependencyPropertyFromControl(this Type type)
        {
            if (type == typeof(TextBox)) return TextBox.TextProperty;
            if (type == typeof(TextBlock)) return TextBlock.TextProperty;
            if (type == typeof(CheckBox)) return ToggleButton.IsCheckedProperty;
            if (type == typeof(ComboBox)) return ComboBox.ItemsSourceProperty;
            if (type == typeof(ListView)) return ListView.ItemsSourceProperty;
            if (type == typeof(Button)) return Button.CommandProperty;
            return null;
        }

        public static DependencyProperty GetDependencyPropertyFromControl(this FrameworkElement fe)
        {
            return GetDependencyPropertyFromControl(fe.GetType());
        }

        public static DependencyProperty GetDependencyPropertyFromName(string propertyName,Type type)
        {
            var descriptor = DependencyPropertyDescriptor.FromName(propertyName,type,type);
            // also, you can use the dependency property itself
            if(descriptor != null)
                return descriptor.DependencyProperty;
            return null;
        }
    }
}

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
United States United States
Sr. application developer currently developing desktop and web applications for the specialty insurance sector. Data integration specialist, interested in learning the latest .Net technologies.

Comments and Discussions