20 changed files with 433 additions and 342 deletions
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using System.Collections.ObjectModel; |
|||
using Microsoft.Windows.Controls.PropertyGrid.Editors; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid |
|||
{ |
|||
public class CustomTypeEditorCollection : ObservableCollection<ICustomTypeEditor> |
|||
{ |
|||
public ICustomTypeEditor this[string propertyName] |
|||
{ |
|||
get |
|||
{ |
|||
foreach (var item in Items) |
|||
{ |
|||
if (item.Properties.Contains(propertyName)) |
|||
return item; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
using System; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Data; |
|||
using System.Windows; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Implementation.EditorProviders |
|||
{ |
|||
public class CheckBoxEditorProvider : ITypeEditorProvider |
|||
{ |
|||
CheckBox _checkbox; |
|||
|
|||
public CheckBoxEditorProvider() |
|||
{ |
|||
_checkbox = new CheckBox(); |
|||
_checkbox.Margin = new Thickness(2, 0, 0, 0); |
|||
} |
|||
|
|||
public void Initialize(PropertyItem propertyItem) |
|||
{ |
|||
ResolveBinding(propertyItem); |
|||
} |
|||
|
|||
public FrameworkElement ResolveEditor() |
|||
{ |
|||
return _checkbox; |
|||
} |
|||
|
|||
private void ResolveBinding(PropertyItem property) |
|||
{ |
|||
var binding = new Binding(property.Name); |
|||
binding.Source = property.Instance; |
|||
binding.ValidatesOnExceptions = true; |
|||
binding.ValidatesOnDataErrors = true; |
|||
|
|||
if (property.IsWriteable) |
|||
binding.Mode = BindingMode.TwoWay; |
|||
else |
|||
binding.Mode = BindingMode.OneWay; |
|||
|
|||
BindingOperations.SetBinding(_checkbox, CheckBox.IsCheckedProperty, binding); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -1,67 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Windows.Controls; |
|||
using System.Windows; |
|||
using System.Windows.Data; |
|||
using System.Reflection; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Implementation.EditorProviders |
|||
{ |
|||
public class EnumComboBoxEditorProvider : ITypeEditorProvider |
|||
{ |
|||
ComboBox _comboBox; |
|||
|
|||
public EnumComboBoxEditorProvider() |
|||
{ |
|||
_comboBox = new ComboBox(); |
|||
} |
|||
|
|||
public void Initialize(PropertyItem propertyItem) |
|||
{ |
|||
ResolveBinding(propertyItem); |
|||
SetItemsSource(propertyItem); |
|||
} |
|||
|
|||
public FrameworkElement ResolveEditor() |
|||
{ |
|||
return _comboBox; |
|||
} |
|||
|
|||
private void ResolveBinding(PropertyItem property) |
|||
{ |
|||
var binding = new Binding(property.Name); |
|||
binding.Source = property.Instance; |
|||
binding.ValidatesOnExceptions = true; |
|||
binding.ValidatesOnDataErrors = true; |
|||
|
|||
if (property.IsWriteable) |
|||
binding.Mode = BindingMode.TwoWay; |
|||
else |
|||
binding.Mode = BindingMode.OneWay; |
|||
|
|||
BindingOperations.SetBinding(_comboBox, ComboBox.SelectedItemProperty, binding); |
|||
} |
|||
|
|||
private void SetItemsSource(PropertyItem property) |
|||
{ |
|||
_comboBox.ItemsSource = GetValues(property.PropertyType); |
|||
} |
|||
|
|||
public static object[] GetValues(Type enumType) |
|||
{ |
|||
List<object> values = new List<object>(); |
|||
|
|||
var fields = from field in enumType.GetFields() |
|||
where field.IsLiteral |
|||
select field; |
|||
|
|||
foreach (FieldInfo field in fields) |
|||
{ |
|||
values.Add(field.GetValue(enumType)); |
|||
} |
|||
|
|||
return values.ToArray(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,110 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Windows.Controls; |
|||
using System.Windows; |
|||
using System.Windows.Data; |
|||
using System.Windows.Media; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Implementation.EditorProviders |
|||
{ |
|||
public class FontComboBoxEditorProvider : ITypeEditorProvider |
|||
{ |
|||
ComboBox _comboBox; |
|||
|
|||
public FontComboBoxEditorProvider() |
|||
{ |
|||
_comboBox = new ComboBox(); |
|||
} |
|||
|
|||
public void Initialize(PropertyItem propertyItem) |
|||
{ |
|||
ResolveBinding(propertyItem); |
|||
SetItemsSource(propertyItem); |
|||
} |
|||
|
|||
public FrameworkElement ResolveEditor() |
|||
{ |
|||
return _comboBox; |
|||
} |
|||
|
|||
private void ResolveBinding(PropertyItem property) |
|||
{ |
|||
var binding = new Binding(property.Name); |
|||
binding.Source = property.Instance; |
|||
binding.ValidatesOnExceptions = true; |
|||
binding.ValidatesOnDataErrors = true; |
|||
|
|||
if (property.IsWriteable) |
|||
binding.Mode = BindingMode.TwoWay; |
|||
else |
|||
binding.Mode = BindingMode.OneWay; |
|||
|
|||
BindingOperations.SetBinding(_comboBox, ComboBox.SelectedItemProperty, binding); |
|||
} |
|||
|
|||
private void SetItemsSource(PropertyItem property) |
|||
{ |
|||
if (property.PropertyType == typeof(FontFamily)) |
|||
{ |
|||
List<FontFamily> fonts = new List<FontFamily>(); |
|||
fonts.Add(new FontFamily("Arial")); |
|||
fonts.Add(new FontFamily("Courier New")); |
|||
fonts.Add(new FontFamily("Times New Roman")); |
|||
fonts.Add(new FontFamily("Batang")); |
|||
fonts.Add(new FontFamily("BatangChe")); |
|||
fonts.Add(new FontFamily("DFKai-SB")); |
|||
fonts.Add(new FontFamily("Dotum")); |
|||
fonts.Add(new FontFamily("DutumChe")); |
|||
fonts.Add(new FontFamily("FangSong")); |
|||
fonts.Add(new FontFamily("GulimChe")); |
|||
fonts.Add(new FontFamily("Gungsuh")); |
|||
fonts.Add(new FontFamily("GungsuhChe")); |
|||
fonts.Add(new FontFamily("KaiTi")); |
|||
fonts.Add(new FontFamily("Malgun Gothic")); |
|||
fonts.Add(new FontFamily("Meiryo")); |
|||
fonts.Add(new FontFamily("Microsoft JhengHei")); |
|||
fonts.Add(new FontFamily("Microsoft YaHei")); |
|||
fonts.Add(new FontFamily("MingLiU")); |
|||
fonts.Add(new FontFamily("MingLiu_HKSCS")); |
|||
fonts.Add(new FontFamily("MingLiu_HKSCS-ExtB")); |
|||
fonts.Add(new FontFamily("MingLiu-ExtB")); |
|||
_comboBox.ItemsSource = fonts; |
|||
} |
|||
else if (property.PropertyType == typeof(FontWeight)) |
|||
{ |
|||
List<FontWeight> list = new List<FontWeight>() |
|||
{ |
|||
FontWeights.Black, FontWeights.Bold, FontWeights.ExtraBlack, FontWeights.ExtraBold, |
|||
FontWeights.ExtraLight, FontWeights.Light, FontWeights.Medium, FontWeights.Normal, FontWeights.SemiBold, |
|||
FontWeights.Thin |
|||
}; |
|||
_comboBox.ItemsSource = list; |
|||
} |
|||
else if (property.PropertyType == typeof(FontStyle)) |
|||
{ |
|||
List<FontStyle> list = new List<FontStyle>() |
|||
{ |
|||
FontStyles.Italic, |
|||
FontStyles.Normal |
|||
}; |
|||
_comboBox.ItemsSource = list; |
|||
} |
|||
else if (property.PropertyType == typeof(FontStretch)) |
|||
{ |
|||
List<FontStretch> list = new List<FontStretch>() |
|||
{ |
|||
FontStretches.Condensed, |
|||
FontStretches.Expanded, |
|||
FontStretches.ExtraCondensed, |
|||
FontStretches.ExtraExpanded, |
|||
FontStretches.Normal, |
|||
FontStretches.SemiCondensed, |
|||
FontStretches.SemiExpanded, |
|||
FontStretches.UltraCondensed, |
|||
FontStretches.UltraExpanded |
|||
}; |
|||
_comboBox.ItemsSource = list; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Implementation.EditorProviders |
|||
{ |
|||
interface ITypeEditorProvider |
|||
{ |
|||
void Initialize(PropertyItem propertyItem); |
|||
FrameworkElement ResolveEditor(); |
|||
} |
|||
} |
|||
@ -1,41 +0,0 @@ |
|||
using System; |
|||
using System.Windows.Data; |
|||
using System.Windows; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Implementation.EditorProviders |
|||
{ |
|||
public class NumericUpDownEditorProvider : ITypeEditorProvider |
|||
{ |
|||
NumericUpDown _numericUpDown; |
|||
|
|||
public NumericUpDownEditorProvider() |
|||
{ |
|||
_numericUpDown = new NumericUpDown(); |
|||
} |
|||
|
|||
public void Initialize(PropertyItem propertyItem) |
|||
{ |
|||
ResolveBinding(propertyItem); |
|||
} |
|||
|
|||
public FrameworkElement ResolveEditor() |
|||
{ |
|||
return _numericUpDown; |
|||
} |
|||
|
|||
private void ResolveBinding(PropertyItem property) |
|||
{ |
|||
var binding = new Binding(property.Name); |
|||
binding.Source = property.Instance; |
|||
binding.ValidatesOnExceptions = true; |
|||
binding.ValidatesOnDataErrors = true; |
|||
|
|||
if (property.IsWriteable) |
|||
binding.Mode = BindingMode.TwoWay; |
|||
else |
|||
binding.Mode = BindingMode.OneWay; |
|||
|
|||
BindingOperations.SetBinding(_numericUpDown, NumericUpDown.ValueProperty, binding); |
|||
} |
|||
} |
|||
} |
|||
@ -1,42 +0,0 @@ |
|||
using System; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Data; |
|||
using System.Windows; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Implementation.EditorProviders |
|||
{ |
|||
public class TextBoxEditorProvider : ITypeEditorProvider |
|||
{ |
|||
FrameworkElement _editor; |
|||
|
|||
public TextBoxEditorProvider() |
|||
{ |
|||
_editor = new TextBox(); |
|||
} |
|||
|
|||
public void Initialize(PropertyItem propertyItem) |
|||
{ |
|||
ResolveBinding(propertyItem); |
|||
} |
|||
|
|||
public FrameworkElement ResolveEditor() |
|||
{ |
|||
return _editor; |
|||
} |
|||
|
|||
private void ResolveBinding(PropertyItem property) |
|||
{ |
|||
var binding = new Binding(property.Name); |
|||
binding.Source = property.Instance; |
|||
binding.ValidatesOnExceptions = true; |
|||
binding.ValidatesOnDataErrors = true; |
|||
|
|||
if (property.IsWriteable) |
|||
binding.Mode = BindingMode.TwoWay; |
|||
else |
|||
binding.Mode = BindingMode.OneWay; |
|||
|
|||
BindingOperations.SetBinding(_editor, TextBox.TextProperty, binding); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System.Windows; |
|||
using System.Windows.Controls; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public class CheckBoxEditor : TypeEditor |
|||
{ |
|||
protected override void Initialize() |
|||
{ |
|||
Editor = new CheckBox(); |
|||
Editor.Margin = new Thickness(4, 0, 0, 0); |
|||
|
|||
ValueProperty = CheckBox.IsCheckedProperty; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public class ColorEditor : TypeEditor |
|||
{ |
|||
protected override void Initialize() |
|||
{ |
|||
Editor = new ColorPicker(); |
|||
ValueProperty = ColorPicker.SelectedColorProperty; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using System.Collections.Generic; |
|||
using System.Windows.Controls; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public abstract class ComboBoxEditor : TypeEditor |
|||
{ |
|||
protected override void Initialize() |
|||
{ |
|||
Editor = new ComboBox(); |
|||
ValueProperty = ComboBox.SelectedItemProperty; |
|||
} |
|||
|
|||
public override void Attach(PropertyItem propertyItem) |
|||
{ |
|||
SetItemsSource(propertyItem); |
|||
base.Attach(propertyItem); |
|||
} |
|||
|
|||
private void SetItemsSource(PropertyItem propertyItem) |
|||
{ |
|||
(Editor as ComboBox).ItemsSource = CreateItemsSource(propertyItem); |
|||
} |
|||
|
|||
protected abstract IList<object> CreateItemsSource(PropertyItem propertyItem); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public class CustomTypeEditor : ICustomTypeEditor |
|||
{ |
|||
public ITypeEditor Editor { get; set; } |
|||
|
|||
private IList<string> _properties = new List<string>(); |
|||
public IList<string> Properties |
|||
{ |
|||
get { return _properties; } |
|||
set { _properties = value; } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using System.Windows.Controls; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public class EnumComboBoxEditor : TypeEditor |
|||
{ |
|||
protected override void Initialize() |
|||
{ |
|||
Editor = new ComboBox(); |
|||
ValueProperty = ComboBox.SelectedItemProperty; |
|||
} |
|||
|
|||
public override void Attach(PropertyItem propertyItem) |
|||
{ |
|||
SetItemsSource(propertyItem); |
|||
base.Attach(propertyItem); |
|||
} |
|||
|
|||
private void SetItemsSource(PropertyItem propertyItem) |
|||
{ |
|||
(Editor as ComboBox).ItemsSource = GetValues(propertyItem.PropertyType); |
|||
} |
|||
|
|||
private static object[] GetValues(Type enumType) |
|||
{ |
|||
List<object> values = new List<object>(); |
|||
|
|||
var fields = enumType.GetFields().Where(x => x.IsLiteral); |
|||
foreach (FieldInfo field in fields) |
|||
{ |
|||
values.Add(field.GetValue(enumType)); |
|||
} |
|||
|
|||
return values.ToArray(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
using System.Collections.Generic; |
|||
using System.Windows; |
|||
using System.Windows.Media; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public class FontComboBoxEditor : ComboBoxEditor |
|||
{ |
|||
protected override IList<object> CreateItemsSource(PropertyItem propertyItem) |
|||
{ |
|||
if (propertyItem.PropertyType == typeof(FontFamily)) |
|||
{ |
|||
return GetFontFamilies(); |
|||
} |
|||
else if (propertyItem.PropertyType == typeof(FontWeight)) |
|||
{ |
|||
return GetFontWeights(); |
|||
} |
|||
else if (propertyItem.PropertyType == typeof(FontStyle)) |
|||
{ |
|||
return GetFontStyles(); |
|||
} |
|||
else if (propertyItem.PropertyType == typeof(FontStretch)) |
|||
{ |
|||
return GetFontStretches(); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private static IList<object> GetFontFamilies() |
|||
{ |
|||
IList<object> fontFamilies = new List<object>(); |
|||
|
|||
//TODO: get all fonts
|
|||
fontFamilies.Add(new FontFamily("Arial")); |
|||
fontFamilies.Add(new FontFamily("Courier New")); |
|||
fontFamilies.Add(new FontFamily("Times New Roman")); |
|||
fontFamilies.Add(new FontFamily("Batang")); |
|||
fontFamilies.Add(new FontFamily("BatangChe")); |
|||
fontFamilies.Add(new FontFamily("DFKai-SB")); |
|||
fontFamilies.Add(new FontFamily("Dotum")); |
|||
fontFamilies.Add(new FontFamily("DutumChe")); |
|||
fontFamilies.Add(new FontFamily("FangSong")); |
|||
fontFamilies.Add(new FontFamily("GulimChe")); |
|||
fontFamilies.Add(new FontFamily("Gungsuh")); |
|||
fontFamilies.Add(new FontFamily("GungsuhChe")); |
|||
fontFamilies.Add(new FontFamily("KaiTi")); |
|||
fontFamilies.Add(new FontFamily("Malgun Gothic")); |
|||
fontFamilies.Add(new FontFamily("Meiryo")); |
|||
fontFamilies.Add(new FontFamily("Microsoft JhengHei")); |
|||
fontFamilies.Add(new FontFamily("Microsoft YaHei")); |
|||
fontFamilies.Add(new FontFamily("MingLiU")); |
|||
fontFamilies.Add(new FontFamily("MingLiu_HKSCS")); |
|||
fontFamilies.Add(new FontFamily("MingLiu_HKSCS-ExtB")); |
|||
fontFamilies.Add(new FontFamily("MingLiu-ExtB")); |
|||
fontFamilies.Add(new FontFamily("Segoe UI")); |
|||
|
|||
return fontFamilies; |
|||
} |
|||
|
|||
private static IList<object> GetFontWeights() |
|||
{ |
|||
return new List<object>() |
|||
{ |
|||
FontWeights.Black, |
|||
FontWeights.Bold, |
|||
FontWeights.ExtraBlack, |
|||
FontWeights.ExtraBold, |
|||
FontWeights.ExtraLight, |
|||
FontWeights.Light, |
|||
FontWeights.Medium, |
|||
FontWeights.Normal, |
|||
FontWeights.SemiBold, |
|||
FontWeights.Thin |
|||
}; |
|||
} |
|||
|
|||
private static IList<object> GetFontStyles() |
|||
{ |
|||
return new List<object>() |
|||
{ |
|||
FontStyles.Italic, |
|||
FontStyles.Normal |
|||
}; |
|||
} |
|||
|
|||
private static IList<object> GetFontStretches() |
|||
{ |
|||
return new List<object>() |
|||
{ |
|||
FontStretches.Condensed, |
|||
FontStretches.Expanded, |
|||
FontStretches.ExtraCondensed, |
|||
FontStretches.ExtraExpanded, |
|||
FontStretches.Normal, |
|||
FontStretches.SemiCondensed, |
|||
FontStretches.SemiExpanded, |
|||
FontStretches.UltraCondensed, |
|||
FontStretches.UltraExpanded |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public interface ICustomTypeEditor |
|||
{ |
|||
ITypeEditor Editor { get; set; } |
|||
IList<string> Properties { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.Windows; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public interface ITypeEditor |
|||
{ |
|||
void Attach(PropertyItem propertyItem); |
|||
FrameworkElement ResolveEditor(); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Windows.Controls; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public class TextBoxEditor : TypeEditor |
|||
{ |
|||
protected override void Initialize() |
|||
{ |
|||
Editor = new TextBox(); |
|||
ValueProperty = TextBox.TextProperty; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
using System; |
|||
using System.Windows; |
|||
using System.Windows.Data; |
|||
|
|||
namespace Microsoft.Windows.Controls.PropertyGrid.Editors |
|||
{ |
|||
public abstract class TypeEditor : ITypeEditor |
|||
{ |
|||
#region Properties
|
|||
|
|||
protected FrameworkElement Editor { get; set; } |
|||
protected DependencyProperty ValueProperty { get; set; } |
|||
|
|||
#endregion //Properties
|
|||
|
|||
#region Constructors
|
|||
|
|||
public TypeEditor() |
|||
{ |
|||
Initialize(); |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region ITypeEditor Members
|
|||
|
|||
public virtual void Attach(PropertyItem propertyItem) |
|||
{ |
|||
ResolveBinding(propertyItem); |
|||
} |
|||
|
|||
public virtual FrameworkElement ResolveEditor() |
|||
{ |
|||
return Editor; |
|||
} |
|||
|
|||
#endregion //ITypeEditor Members
|
|||
|
|||
#region Methods
|
|||
|
|||
protected abstract void Initialize(); |
|||
|
|||
protected virtual void ResolveBinding(PropertyItem propertyItem) |
|||
{ |
|||
var _binding = new Binding("Value"); |
|||
_binding.Source = propertyItem; |
|||
_binding.ValidatesOnExceptions = true; |
|||
_binding.ValidatesOnDataErrors = true; |
|||
_binding.Mode = propertyItem.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay; |
|||
_binding.Converter = CreateConverter(); |
|||
BindingOperations.SetBinding(Editor, ValueProperty, _binding); |
|||
} |
|||
|
|||
protected virtual IValueConverter CreateConverter() |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
#endregion //Methods
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue