M
Mark Olbert
I have a UserControl ("CustomContainer") to which I am adding instances of another custom control
("CustomTextBox"). When the CustomTextBox instance accesses a particular property of the
CustomContainer it's on, it needs to be "redirected" to a "shadow" property maintained by the
CustomContainer's designer ("CustomContainerDesigner").
Unfortunately, the CustomTextBox keeps referring to the CustomContainer's "version" of the
property... and I don't understand why.
Here're snippets showing what I've done:
// this designer is referenced via a Designer attribute on the CustomContainer class
// it is marked as being typeof(IRootDesigner) [nothing else seems to actually associate it with
// the CustomContainer's design surface]
public class CustomContainerDesigner : DocumentDesigner
{
// this is the "shadow" property
public SqlDataPackage SqlDataPackage
{
get
{
if( thePkg == null )
{
if( ((CustomContainer) this.Component).SqlDataPackageType != null )
{
// theCtl is set to be the CustomContainer instance
ConstructorInfo dpCtor = theCtl.SqlDataPackageType.GetConstructor(System.Type.EmptyTypes);
thePkg = (SqlDataPackage) dpCtor.Invoke(null);
}
}
return thePkg;
}
set { thePkg = value; }
}
protected override void PreFilterProperties( IDictionary properties )
{
// replace the RecordBase's SqlDataPackage property with a shadow
// property of the same name provided by this designer
base.PreFilterProperties(properties);
PropertyDescriptor prop = TypeDescriptor.CreateProperty(this.GetType(), "SqlDataPackage",
typeof(SqlDataPackage), new Attribute[] { new BrowsableAttribute(false) });
// this should replace the CustomComponent's SqlDataPackage property with
// the shadow property
properties.Remove("SqlDataPackage");
properties.Add("SqlDataPackage", prop);
}
}
public class CustomTextBox
{
public SqlDataPackage SqlDataPackage
{
get
{
// ***********************************
// this is where I want to access the shadow property
// ***********************************
if( !(this.Parent is CustomContainer) ) return null;
return ((CustomContainer) this.Parent).SqlDataPackage;
}
set
{
// no op
}
}
}
I'm wondering if the problem is that the expression this.Parent (which is a reference to the
CustomContainer that my CustomTextBox instance is on) >>doesn't<< refer to the instance of
CustomContainer that's being designed, so the shadow property never gets accessed. If that's the
case, how do I provide shadow properties of a control container to the controls that are in the
container?
Any and all suggestions welcome!
- Mark
("CustomTextBox"). When the CustomTextBox instance accesses a particular property of the
CustomContainer it's on, it needs to be "redirected" to a "shadow" property maintained by the
CustomContainer's designer ("CustomContainerDesigner").
Unfortunately, the CustomTextBox keeps referring to the CustomContainer's "version" of the
property... and I don't understand why.
Here're snippets showing what I've done:
// this designer is referenced via a Designer attribute on the CustomContainer class
// it is marked as being typeof(IRootDesigner) [nothing else seems to actually associate it with
// the CustomContainer's design surface]
public class CustomContainerDesigner : DocumentDesigner
{
// this is the "shadow" property
public SqlDataPackage SqlDataPackage
{
get
{
if( thePkg == null )
{
if( ((CustomContainer) this.Component).SqlDataPackageType != null )
{
// theCtl is set to be the CustomContainer instance
ConstructorInfo dpCtor = theCtl.SqlDataPackageType.GetConstructor(System.Type.EmptyTypes);
thePkg = (SqlDataPackage) dpCtor.Invoke(null);
}
}
return thePkg;
}
set { thePkg = value; }
}
protected override void PreFilterProperties( IDictionary properties )
{
// replace the RecordBase's SqlDataPackage property with a shadow
// property of the same name provided by this designer
base.PreFilterProperties(properties);
PropertyDescriptor prop = TypeDescriptor.CreateProperty(this.GetType(), "SqlDataPackage",
typeof(SqlDataPackage), new Attribute[] { new BrowsableAttribute(false) });
// this should replace the CustomComponent's SqlDataPackage property with
// the shadow property
properties.Remove("SqlDataPackage");
properties.Add("SqlDataPackage", prop);
}
}
public class CustomTextBox
{
public SqlDataPackage SqlDataPackage
{
get
{
// ***********************************
// this is where I want to access the shadow property
// ***********************************
if( !(this.Parent is CustomContainer) ) return null;
return ((CustomContainer) this.Parent).SqlDataPackage;
}
set
{
// no op
}
}
}
I'm wondering if the problem is that the expression this.Parent (which is a reference to the
CustomContainer that my CustomTextBox instance is on) >>doesn't<< refer to the instance of
CustomContainer that's being designed, so the shadow property never gets accessed. If that's the
case, how do I provide shadow properties of a control container to the controls that are in the
container?
Any and all suggestions welcome!
- Mark