change a property does not update custom control

A

--== Alain ==--

Hi,

I have some issue with my custom control.
When i change my property "GridLine.Color" my custom control should
redraw its border with the specified color. However, nothing happens.

therefore based on an example from a book i implemented an eventhandler
and tried to manage it like that... but still nothing.

Here is my code example :

public class CGridLine
{
public event EventHandler PropertyChanged;
private Color m_GridLinesColor;

public Color Color
{
get
{
return this.m_GridLinesColor;
}
set
{
this.m_GridLinesColor = value;
this.OnPropertyChanged(EventArgs.Empty);
}
}
....
private void OnPropertyChanged(EventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
}

here is my custom control code :
....
public CGridLine GridLines
{
get
{
return this.m_GridLines;
}
set
{
this.m_GridLines = value;
if (GridLinePropertyChanged != null)
{
this.m_GridLines.PropertyChanged -= this.GridLinePropertyChanged;
}
this.GridLinePropertyChanged = new
EventHandler(GridLines.PropertyChanged);
this.m_GridLines.PropertyChanged += this.GridLinePropertyChanged;
this.Invalidate();
}
}
....


Could someone give me an example how to update during design time, the
custom control using eventhandler ?

thanks a lot,

Al.
 
M

Marc Gravell

First: for default binding notification events to work, the name is
important: yours should be ColorChanged, not PropertyChanged. This is
a good approach to stick to, as it is a: expected, and b: necessary
for PropertyDescriptor.{Add|Remove}ValueChanged to work correctly
using the default reflection model.

However! There is nothing in the sample provided that would cause it
to redraw when the Color changes; you need to cause invalidate etc -
unless that is hidden in GridLinePropertyChanged (which you haven't
shown us).

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top