Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Designer Considerations

 
 
Old 11-07-2007   #1 (permalink)
escher4096


 
 

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 SpecsSystem Spec
Old 11-07-2007   #2 (permalink)
Laurent Bugnion, MVP


 
 

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
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
My System SpecsSystem Spec
Old 11-08-2007   #3 (permalink)
escher4096


 
 

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
Hi,

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 SpecsSystem Spec
 

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46