.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Foundations: Dependency Properties And Notifications

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Windows Presentation Foundation dependency properties don't always play well with others. Learn how you can compensate for their lack of notification events.

Charles Petzold

MSDN Magazine September 2008

View Complete Post

More Related Resource Links

Dependency Properties

When you begin to develop appliations with WPF, you will soon stumble across DependencyProperties. They look quite similar to normal .NET properties, but the concept behind is much more complex and powerful

Dependency Properties get/set method question



I recently added a new dependency property to a control of mine and bound its value to my control's ViewModel.  I put custom code in the Get method of the dependency property and saw the return value from that method does not come across to the ViewModel.  After some research, it seems that when the XAML parser attempts to get or set this property's value that it does not use these get/set methods at all.  So to make this DP useful for my scenario, I have to figure out another way to set this value ahead of time, i.e. through code.

My question is, what is the point of these get/set methods for your DP if the XAML parser isn't going to use them?  Is it really all that useful to use these in code?  I would imagine DP's are mostly being used for the purpose of data binding in which case it'd be helpful to be able to define how WPF will get and set the value.  I liken this scenario to a public property with a private backing field, and having WinForms or whatever just directly access the backing field and skipping my property's getter/setter, which would obviously be a bug.

I'd appreciate any insight on this.

How do I bind these dependency properties?


I have two custom classes: "Foo" with a dependency property called "FooValue", and "Bar" with a dependency property called "BarValue". I can declare these in Xaml and bind them the usual way like so:

	<my:Foo x:Name="foo" x:Key="foo" FooValue="Hello World!">
	<my:Bar x:Key="bar" BarValue="{Binding Source={StaticResource foo},Path=FooValue}"/>

But what if Bar is a member of Foo? How do I do the binding then?

<my:Foo x:Name="foo" x:Key="foo" FooValue="Hello World!">
		<my:Bar BarValue="{Binding *** what goes here? ***}"/>

I can't bind to the "foo" key because the parent object is still in the process of being created and doesn't exist yet. I've also tried using FindAncestor but that doesn't seem to work with custom classes. What's the mechanism that controls use to get it to work?

How and When Dependency Properties are bound and evaluated?



I have a custom combo box control derived from existing WPF combo box. This custom combo has a DP called AssociatedEnum, once set it evaluates the enum menbers and adds them to Items collection.. However all this enumerating over available values, is done in Combo's loaded event Is it reasonable to assume that all the bindings on Dependency props will be set and evaluated to their initial values during the controls load event.

I am not very sure about this as i have seen some instances where the Binding is evaluated post load event, which defeats entire purpose of writing the selection in load event. My question should i go ahead and implement property changed handler for this dependency property??

Regards, v703218

link | edit |

Can you add Dependency Properties to custom activities?


I'm trying to add a simple DependencyProperty to a base activity of mine that inherits from NativeActivity.  Is this possible?  It doesn't seem so since the SetValue and GetValue methods of the dependency property definition are not recognized.

I want a dependency property because I'd like to be able to check the property from a Trigger in the activity designer ... like this:

            <Trigger Property="{Binding Path=ModelItem.IsEnabled}" Value="True">
              <Setter TargetName="Header" Property="<

WCF Tip: Using Properties in Service Contracts

you'll notice all of the Service Contracts are implemented with interfaces containing only methods. For the longest time I thought that's all that was supported, until I thought about it a little more. In C# land, properties are simply wrappers around a get method and set method, so why wouldn't we be able to use properties in a service contract? Well the answer is we can.

Automatic vs Explicit Properties

If the reason that motivated the change from automatically implemented property to explicitly implemented property was to change the semantics of the property then you should evaluate whether the desired semantics when accessing the property from within the class are identical to or different from the desired semantics when accessing the property from outside the class.

Xml File Methods and Properties

Method and Properties of XmlTextWriter class:
The XmlWriter class is a base class that outputs an XML data structure. It has methods to sequentially write XML elements in a proper hierarchy to create an XML file or other types of output streams. The System.Xml namespace provides support for the XmlWriter. It must be imported to the ASP.NET page with the directive

<%@ Import Namespace="System.Xml" %>

The XmlTextWriter

XmlWriter is an abstract class that is implemented as an extended XMLTextWriter class. The XmlTextWriter writes a sequence of XML nodes one element at a time. Output can be written to an XML file, although other streams of output data can be produced. It can create a new file or overwrite an existing file. Its non-cached writing techniques provides very fast generation of an output stream.

C# conversion to VB and properties


I am trying to implement image caching for a web application and I found some code on the Internet that implements an HttpHandler that does this. The code was in C# and since my web app is written in VB, I decided to convert the code to VB. I managed to convert everything except the following code (in bold):

public class FileExtensionCollection : ConfigurationElementCollection
        public override ConfigurationElementCollectionType CollectionType
                return ConfigurationElementCollectionType.AddRemoveClearMap;

        public FileExtension this[int index]
            get { return (FileExtension)BaseGet(index); }

using reflection to emit properties to the top of the entity graph


I've got a class

  public class Criminal

public HouseholdMember[] LiedAboutFSHousehold { get; set; }

      public HouseholdMember[] FoodstampTrafficingHousehold { get; set; }
HouseholdMember inherits Person, as do many other classes.  

  public class HouseholdMember: Person


What I&#

Foundations: Service Bus Buffers


Learn some advanced Windows Communication Foundation programming techniques as Juval Lowy begins an in-depth examination of the Windows Azure AppFabric service bus, focusing first on buffers.

Juval Lowy

MSDN Magazine May 2010

Foundations: Discover a New WCF with Discovery


Juval Lowy explains how the industry-standard discovery solution enables clients to discover available addresses for WCF calls at runtime, and he provides tools and helper classes to simplify the process.

Juval Lowy

MSDN Magazine January 2010

Foundations: Workflow Services for Local Communication


This month's column describes how to use WCF for communication between a workflow and a host application in Windows Workflow Foundation 3. This knowledge should help developers with their efforts using WF3 and prepare them for WF4, where WCF is the only abstraction over queues (referred to as "bookmarks" in WF4) that ships with the framework.

Matthew Milner

MSDN Magazine November 2009

Inside Microsoft patterns & practices: Dependency Injection in Libraries


This article discusses how to write a library or framework that uses the Dependency Injection pattern and how the change in focus affects the usage of the pattern.

Chris Tavares

MSDN Magazine November 2009

Foundations: Routers in the Service Bus


This article describes aspects of using routers with the .NET service bus, especially their use in a message-based architecture.

Juval Lowy

MSDN Magazine October 2009

Foundations: Charting with DataTemplates


For WPF programmers, one major revelation about the power of the DataTemplate comes with a demonstration of how XAML can turn business objects into bar charts. This column explores how to use DataTemplates to create different types of charts.

Charles Petzold

MSDN Magazine September 2009

Foundations: Windows Workflow Design Patterns


Design patterns provide a common, repeatable approach to solving software development tasks, and many different patterns can describe how to accomplish a certain goal in code. When developers begin working with Windows Workflow Foundation (WF), they often ask about how to accomplish common tasks with the technology. This month's column discusses several design patterns used in WF.

Matthew Milner

MSDN Magazine August 2009

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend