Windows Vista Forums

Design time only DependencyProperty

  1. #1


    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

      My System SpecsSystem Spec

  2. #2


    Laurent Bugnion, MVP Guest

    Re: Design time only DependencyProperty

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

  3. #3


    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



      My System SpecsSystem Spec

  4. #4


    Andy Guest

    Re: Design time only DependencyProperty

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

Design time only DependencyProperty

Similar Threads
Thread Forum
Setting properties on hosted toolstrip control at design time
I created my own toolstrip control using ToolStripControlHost. When I add this to a toolstrip, I want to adjust the properties of the hosted...
.NET General
Web Design
Hi guys, I'd like to know your thoughts on what's a good web design software. I'm not that in to coding so I'd like one with simple to use, drag...
Software
Copy DependencyProperty with Reflection
I need to copy (clone) Properties of an FrameworkElement. For the normal properties it's simple. But how can I find and copy the...
Avalon
No notification when a DependencyProperty value has changed?
I am working on a FrameworkElement called Plot which has to dynamically create TextBlocks. All of them should use the same font size, font family,...
Avalon
obtain type of dependencyproperty
When I register a DepencyPorperty I can specify what type it is supposed to store. How can I find out what type is set for a DepenencyProperty of a...
Avalon
C++/CLI based DependencyProperty example
Is there any examples of showing how one might add a DependencyProperty to a C++ class? All of the examples I've found are C# based and I'm not...
Avalon
How to bind a Trigger to a user defined DependencyProperty
Hi I do the following inside my code public partial class ShoppingCart : StackPanel, INotifyPropertyChanged { public ShoppingCart() {...
Avalon