Posted 14 years ago
by Ong Chuan Eng

Hi ,
There is double property FontSize in the viewmodel class, which is binded to property grid using selected object.
I have added custom combo editor to the property to display Renage of values.
as below.
private double _fontSize;
[Category("Line Properties")]
[Editor(typeof(CustomDoublePropertyEditor), typeof(PropertyEditor))]
public double FontSize
{
get
{
return _fontSize;
}
set
{
_fontSize = value;
Changed("FontSize");
}
}
public class CustomDoublePropertyEditor : ActiproSoftware.Windows.Controls.Editors.Interop.PropertyGrid.PropertyEditors.DoublePropertyEditor
{
protected override DataTemplate CreateDataTemplate()
{
DataTemplate cardLayout = new DataTemplate();
//set up the stack panel
FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(DockPanel));
spFactory.Name = "myCustomFactory";
FrameworkElementFactory combo = new FrameworkElementFactory(typeof(ComboBox));
Binding selectedItem = new Binding("Value");
selectedItem.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyGridDataAccessorItem), 1);
selectedItem.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;
combo.SetBinding(ComboBox.SelectedItemProperty, selectedItem);
ObservableCollection<double> itemSource = new ObservableCollection<double>();
for (double i = LineViewModel.MinmunFontSize; i <= LineViewModel.MaximumFontSize; i++)
itemSource.Add(i);
combo.SetValue(ComboBox.ItemsSourceProperty, itemSource);
spFactory.AppendChild(combo);
cardLayout.VisualTree = spFactory;
return cardLayout;
}
public CustomDoublePropertyEditor()
{
this.DropDownButtonVisibility = Visibility.Visible;
}
}
Now the issue is the ItemSource of the comboBox should change dymanically.
ItemSource is a Range from MinValue to MaxValue. There are properties as MinmumValue and MaxValue in the same ViewModel Class.
How to Bind the ItemSource of the combo to a property in the same viewmodel class?
Thanks in advance.
[Modified at 08/03/2011 06:50 AM]
There is double property FontSize in the viewmodel class, which is binded to property grid using selected object.
I have added custom combo editor to the property to display Renage of values.
as below.
private double _fontSize;
[Category("Line Properties")]
[Editor(typeof(CustomDoublePropertyEditor), typeof(PropertyEditor))]
public double FontSize
{
get
{
return _fontSize;
}
set
{
_fontSize = value;
Changed("FontSize");
}
}
public class CustomDoublePropertyEditor : ActiproSoftware.Windows.Controls.Editors.Interop.PropertyGrid.PropertyEditors.DoublePropertyEditor
{
protected override DataTemplate CreateDataTemplate()
{
DataTemplate cardLayout = new DataTemplate();
//set up the stack panel
FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(DockPanel));
spFactory.Name = "myCustomFactory";
FrameworkElementFactory combo = new FrameworkElementFactory(typeof(ComboBox));
Binding selectedItem = new Binding("Value");
selectedItem.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyGridDataAccessorItem), 1);
selectedItem.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;
combo.SetBinding(ComboBox.SelectedItemProperty, selectedItem);
ObservableCollection<double> itemSource = new ObservableCollection<double>();
for (double i = LineViewModel.MinmunFontSize; i <= LineViewModel.MaximumFontSize; i++)
itemSource.Add(i);
combo.SetValue(ComboBox.ItemsSourceProperty, itemSource);
spFactory.AppendChild(combo);
cardLayout.VisualTree = spFactory;
return cardLayout;
}
public CustomDoublePropertyEditor()
{
this.DropDownButtonVisibility = Visibility.Visible;
}
}
Now the issue is the ItemSource of the comboBox should change dymanically.
ItemSource is a Range from MinValue to MaxValue. There are properties as MinmumValue and MaxValue in the same ViewModel Class.
How to Bind the ItemSource of the combo to a property in the same viewmodel class?
Thanks in advance.
[Modified at 08/03/2011 06:50 AM]