Hi,
We have a project requirement that when the user changes the property in the property grid control should display the changed value in RED(change forecolor).
Presently we have only one option to set "ModifiedPropertyDisplayMode" which allows BoldValue and ItalicValue options.
Please suggest a way to achive this.
We made sample application to set ForeColor to Red once property has been changed, but it requires to call PropertyControl.Refresh(). Please have a look at following example and suggest the way to avoid call "Refresh()" which flickers the entire property items.
Example:Thanks,
Balaram
[Modified at 05/01/2009 04:48 AM]
We have a project requirement that when the user changes the property in the property grid control should display the changed value in RED(change forecolor).
Presently we have only one option to set "ModifiedPropertyDisplayMode" which allows BoldValue and ItalicValue options.
Please suggest a way to achive this.
We made sample application to set ForeColor to Red once property has been changed, but it requires to call PropertyControl.Refresh(). Please have a look at following example and suggest the way to avoid call "Refresh()" which flickers the entire property items.
Example:
class MyBackGround // Sample Class for custom binding
{
private SolidColorBrush backgroundBrush = null;
public MyBackGround()
{
backgroundBrush = new SolidColorBrush(Colors.Black);
}
public SolidColorBrush BackgroundColor
{
set { backgroundBrush = value; }
get { return backgroundBrush; }
}
}
SolidColorBrush redBrush = new SolidColorBrush(Colors.Red);
SolidColorBrush blackBrush = new SolidColorBrush(Colors.Black);
MyBackGround myback = new MyBackGround(); // For Sample it is a class member.
private void Init() // My Init Function
{
Binding backGroundBinding = new Binding("BackgroundColor");
backGroundBinding.Source = myback;
DataTemplate dataTemplate = new DataTemplate();
FrameworkElementFactory testFec = new FrameworkElementFactory(typeof(TextBox));
testFec.SetBinding(TextBox.TextProperty, new Binding("Value") { RelativeSource = new RelativeSource() { AncestorType = typeof(IPropertyDataAccessor) } });
testFec.SetBinding(TextBox.ForegroundProperty, backGroundBinding);
dataTemplate.VisualTree = testFec;
PropertyGridPropertyItem item = new PropertyGridPropertyItem();
item.DisplayName = "Test Property";
item.Description = "Description of test";
item.Category = "General Properties";
item.ValueTemplate = dataTemplate;
item.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(item_PropertyChanged);
item.Value = "Maulik";
item.ValueName = "testBackG";
this.propGrid.Properties.Add(item); // Add it.
}
void item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName != "Value")
{
return;
}
if (propGrid.Properties.Count <= 0)
return;
PropertyGridPropertyItem propItem = (PropertyGridPropertyItem)sender;
if (propItem.ValueName == "testBackG")
{
if ((bool)propItem.IsModified)
{
myback.BackgroundColor = redBrush;
propGrid.Refresh(); // IF We comment it, the effect is not coming.
}
}
}
Balaram
[Modified at 05/01/2009 04:48 AM]