-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PropertyEditor expose ControlInfo getter #29
Comments
Hello, To customize that ControlInfo, you have to create a derived class from PropertyEditor and override the Configure() method, like this: [Export(typeof(IInitializable))]
[Export(typeof(IControlHostClient))]
[Export(typeof(PropertyEditor))]
[Export(typeof(MyPropertyEditor))]
[PartCreationPolicy(CreationPolicy.Any)]
public class MyPropertyEditor : PropertyEditor
{
[ImportingConstructor]
public MyPropertyEditor(
ICommandService commandService,
IControlHostService controlHostService,
IContextRegistry contextRegistry)
: base(commandService, controlHostService, contextRegistry)
{
}
protected override void Configure(out PropertyGrid propertyGrid, out ControlInfo controlInfo)
{
base.Configure(out propertyGrid, out controlInfo);
controlInfo.Name = "My Name";
}
} Then in your TypeCatalog, replace 'PropertyEditor' with 'MyPropertyEditor'. I know creating a derived class can be a pain, but an accessor would have the problem where for some of the ControlInfo's properties, you would have to set them at the right time (before the RegisterControl() method gets called on the ControlHostService). That Configure() method makes sure that the ControlInfo gets customized at the correct time. |
I can't do that because I'm trying to pass into the MyPropertyEditor the title to begin with so as to share it among a multitude of propertyEditors, and since base calls Configure before any of the contents of the constructor I can't do it like that. What about passing in the title as a parameter of a PropertyEditor constructor? |
You could pass the title string as a parameter to MyPropertyEditor's constructor and then store it in a field and then use that string in the Configure method, right? |
I don't think that works: http://www.csharp411.com/c-object-initialization/ The base class's constructor is called before the derived class's constructor |
Doh! You're absolutely right. I didn't think that all the way through. I looked at a couple of work-arounds and I think I have a good solution. Since calling a virtual method in a constructor is bad practice anyway, how about we move the call to Configure() to be from the Initialize() method? Then you can pass the title string or even a whole ControlInfo object into your constructor and Configure will be able to work with whatever fields/properties it needs. I checked in an updated PropertyEditor.cs. Would you mind trying it out? |
That works. I still think taking an extra constructor parameter is better because then I don't have to derive a new class to change the text from "Property Editor", but it'll do. |
Thanks, Colin. |
Did this get rolled back out? One of our guys took latest from the repository and it doesn't appear to be in PropertyEditor? |
It appears to have disappeared after Nov 8, 2014. Our theory is that it got merged over and the changes from Oct 7th to Nov 8 may have been blitzed? None of us over here use git much. |
The Configure() method is now called from Initialize() instead of from the constructor. This will allow derived classes to use parameters from their constructors in their override of Configure(). Closes #29. Added the DefaultPropertyEditingContext property to allow client code to customize which property descriptors are used for the current selection set. Closes #28.
Weird! I don't know what happened, but my changes from 10/16/2014 and 10/30/2014 to this file were lost or did I really never check it in? I'm not sure. I just checked in the changes (again?). |
You did check them in because that's how I got them to test them. Look at the parent branches for the merge on Nov 8. It seems suspect to me? I'd also look at the other changes between those dates to be sure. |
a944cc5 original commit. |
Thanks, Colin. I thought I was going crazy for a minute there. It looks like the commit on 11/8 has the wrong parent somehow. I don't know Git well enough to understand how this happened. So, we lost changes from 10/7, 10/16, 10/30, and 10/31. I'll have to figure this out tomorrow. |
Thanks Ron. |
Jeez, what a mess. I restored 'master' to how I think it should be, but I've lost a bunch of commit messages. |
I'd like to change the title of the Property Control in a PropertyEditor, but I don't have access to the ControlInfo to change it's Name, and it's marked as private readonly as well so I have no workaround
Could I get an accessor for m_controlInfo please?
The text was updated successfully, but these errors were encountered: