![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Designer Considerations Is it possible to have a constructor or a method that can only be used by the designer? The designer requires a default (empty) constructor but I do not want to allow an empty constructor into my API. If I could have an empty one that is some how marked (attribute maybe) to only be allowable in the designer that would rock. I have no luck searching for something like this. Thanks -Cam |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Designer Considerations Hi, escher4096 wrote: Quote: > Is it possible to have a constructor or a method that can only be used > by the designer? The designer requires a default (empty) constructor > but I do not want to allow an empty constructor into my API. If I > could have an empty one that is some how marked (attribute maybe) to > only be allowable in the designer that would rock. > > I have no luck searching for something like this. > > Thanks > > -Cam talking about Blend, or the WPF designer in Visual Studio (Cider)? And for which type of object? A Custom Control? If you want to allow a method to be used by the designer, but not by anyone else, you have two options: 1) Enclose the method in a #if DEBUG #endif block. This will exclude the code from the release version of your library/application. The code will only be available in the debug version. 2) Inside the method, add the following code: public Music() { if (!DesignerProperties.GetIsInDesignMode(new DependencyObject())) { throw new ApplicationException("This method may only be used by the designer"); } } HTH, Laurent -- Laurent Bugnion [MVP ASP.NET] Software engineering, Blog: http://www.galasoft.ch PhotoAlbum: http://www.galasoft.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Designer Considerations On Nov 7, 10:56 am, "Laurent Bugnion, MVP" <galasoft...@xxxxxx> wrote: Quote: > Hi, > > escher4096 wrote: Quote: > > Is it possible to have a constructor or a method that can only be used > > by the designer? The designer requires a default (empty) constructor > > but I do not want to allow an empty constructor into my API. If I > > could have an empty one that is some how marked (attribute maybe) to > > only be allowable in the designer that would rock. Quote: > > I have no luck searching for something like this. Quote: > > Thanks Quote: > > -Cam > In which case did the designer ask for an empty constructor? Are you > talking about Blend, or the WPF designer in Visual Studio (Cider)? And > for which type of object? A Custom Control? > > If you want to allow a method to be used by the designer, but not by > anyone else, you have two options: > > 1) Enclose the method in a > #if DEBUG > #endif > block. This will exclude the code from the release version of your > library/application. The code will only be available in the debug version. > > 2) Inside the method, add the following code: > > public Music() > { > if (!DesignerProperties.GetIsInDesignMode(new DependencyObject())) > { > throw new ApplicationException("This method may only be used by the > designer"); > } > > } > > HTH, > Laurent > -- > Laurent Bugnion [MVP ASP.NET] > Software engineering, Blog:http://www.galasoft.ch > PhotoAlbum:http://www.galasoft.ch/pictures > Support children in Calcutta:http://www.calcutta-espoir.ch I have a custom window object and the WPF Designer in Visual Studio insists on an empty constructor for it. I will try your code snippet for it. Thanks -Cam |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Suggestions, Considerations, and Issues with WLM9 beta | Live Messenger | |||
| designer | Vista General | |||
| BitLocker Post OS-Install - Boot & Partition Considerations | Vista security | |||
| RE: ATI considerations | Vista Games | |||