WPF: Autogenerate a Private Dependency Property ?

J

Jules Winfield

Hello.

I frequently need to create private dependency properties to facilitate data
binding. For example, I recently bound the "IsEnabled" property of the OK
button to a private Boolean property indicating whether or not a login is
currently in process. So, time after time, I'm writing code like this:

private static readonly DependencyProperty IsLoginInProgProperty =
DependencyProperty.Register("IsLoginInProg",typeof(bool),typeof(LoginPopup));
private bool IsLoginInProg{
get{return (bool)GetValue(IsLoginInProgProperty);}
set{SetValue(IsLoginInProgProperty,value);}
}

Does Visual Studio 2008 provide any facility for automatically generating
this type of code? In the case above, for example, I could simply specify
that I want a bool-typed dependency property called "IsLoginInProg" and the
necessary code would be inserted into my class.

Is this type of feature currently available?

Thanks,

Jules
 
L

Linda Liu[MSFT]

Hi Jules,
Does Visual Studio 2008 provide any facility for automatically generating
this type of code?

No, Visual Studio 2008 doesn't provide such a facility for automatically
generating this type of code so far.

But it does provide a template for the Dependency Property code snippet,
i.e type "propdp" in the code editor and press the "TAB" key twice, and
then VS2008 will insert a Dependency Property code snippet.

In addition, if possible you can define Dependency Properties in a base
class in your project and then derive other classes from this base class.
So all the derived classes can use the Dependency Properties which are
defined in the base class directly and needn't define them any more.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jules Winfield

But it does provide a template for the Dependency Property code snippet,
i.e type "propdp" in the code editor and press the "TAB" key twice, and
then VS2008 will insert a Dependency Property code snippet.

Hey, that's neat!! I've never seen that trick before. What other special
codes are there?
 
L

Linda Liu

Hi Jules,

Thank you for your reply!

You can check other code snippets in VS2008 IDE. In detail, select menu
Tools->Code Snippets Manager. In the "Code Snippets Manager" dialog, you'll
see all available code snippets.

In addition, you can write your own or download 3rd party code snippets and
then import them in VS2008 by clicking the "Import" button in the "Code
Snippets Manager" dialog.

FYI, you can find many 3rd party code snippets from the following web site:

http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=code snippet

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top