Click here to Skip to main content
15,897,704 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.7K   3.4K   108  
Form designer with editable display properties and bindings. Generates XAML forms.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Data;
using WPFFormDesigner.WPFControlUtils;


namespace WPFFormDesigner.Converters
{
    public class ListViewAddButtonConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //ObservableCollectionItem oci = null;
            Button btn = value as Button;
            if(btn != null)
            {
                StackPanel sp = UIHelper.FindParent<StackPanel>(btn,false);
                if(sp != null)
                {
                    ListView lv = UIHelper.FindFirstChild<ListView>(sp,false);
                    if (lv != null)
                    {
                        Binding binding = BindingOperations.GetBinding(lv, ListView.ItemsSourceProperty);
                        if (binding != null)
                        {
                            //oci = new ObservableCollectionItem
                            //          {
                            //              BindingPath = binding.Path.Path,
                            //              ListViewName = lv.Name
                            //          };
                            //return oci;
                            return binding.Path.Path;
                        }
                    }
                }
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            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