• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Design time only DependencyProperty

A
#1
Hi,

I'm creating a user control in WPF, and I would like to have a
property which can only be set in design time. I'm using this
property as a parameter to another wpf data provider control.

I don't see anything to set that the dependency property can only be
changed at design time, but I have found how to determine if the
control is in design time or run-time. I still don't know what the
proper way to handle this is. Do I coerce the value? Validate and
throw an exception if it changes during run time?

What's the best way to accomplish this? I would like the property to
be changable via the property grid like other wpf / winforms controls
(since the wpf control will be hosted in a winforms app).

Thanks
Andy
 

My Computer

L

Laurent Bugnion, MVP

#2
Hi,

Andy wrote:

> Hi,
>
> I'm creating a user control in WPF, and I would like to have a
> property which can only be set in design time. I'm using this
> property as a parameter to another wpf data provider control.
>
> I don't see anything to set that the dependency property can only be
> changed at design time, but I have found how to determine if the
> control is in design time or run-time. I still don't know what the
> proper way to handle this is. Do I coerce the value? Validate and
> throw an exception if it changes during run time?
>
> What's the best way to accomplish this? I would like the property to
> be changable via the property grid like other wpf / winforms controls
> (since the wpf control will be hosted in a winforms app).
>
> Thanks
> Andy
It depends if you want to explicitly warn your users against setting
this property during run time, in which case I would use a Validation
rule, or to silently forbid changing the value, in which case you should
coerce the value.

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 Computer

S

Serge Baltic

#3
Hello,

If you're setting the property at design time, it will affect presentation
in the Designer only. When your program is run, the property will not be
set, as the program is not in Design mode when it's run, right? :)

So you probably want to prevent the property changes after some moment —
after the control retrieves the data for the initial value, for example.
That should be the condition for cancelling the further changes. Probably,
Validation is a good way to achieve it.

(H) Serge
 

My Computer

A
#4
On Dec 26, 7:26 pm, "Laurent Bugnion, MVP" <galasoft...@xxxxxx>
wrote:

> It depends if you want to explicitly warn your users against setting
> this property during run time, in which case I would use a Validation
> rule, or to silently forbid changing the value, in which case you should
> coerce the value.
Yes, it should be an error to change it during run time. When used
in a running program, the control shouldn't let the property value
change. A developer must change it in the property grid.

I'll go with validation.

Thanks!
Andy
 

My Computer