Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Design time only DependencyProperty

Closed Thread
 
Thread Tools Display Modes
Old 12-26-2007   #1 (permalink)
Andy
Guest


 

Design time only DependencyProperty

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
Old 12-26-2007   #2 (permalink)
Laurent Bugnion, MVP
Guest


 

Re: Design time only DependencyProperty

Hi,

Andy wrote:
Quote:

> 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
Old 12-27-2007   #3 (permalink)
Serge Baltic
Guest


 

Re: Design time only DependencyProperty

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


Old 12-27-2007   #4 (permalink)
Andy
Guest


 

Re: Design time only DependencyProperty

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

> 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
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy DependencyProperty with Reflection Horst Klein Avalon 2 07-10-2007 08:32 AM
No notification when a DependencyProperty value has changed? fö Avalon 0 06-28-2007 11:20 AM
obtain type of dependencyproperty Robert Ludig Avalon 2 01-12-2007 09:26 AM
C++/CLI based DependencyProperty example =?Utf-8?B?Sm9obiBEdW5u?= Avalon 0 08-23-2006 04:57 PM
How to bind a Trigger to a user defined DependencyProperty Philippe Lavoie Avalon 1 03-15-2006 03:21 PM








Vistax64.com 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 2005-2008

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 47 48 49 50