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