views:

19

answers:

1

In WPF-XAML, determining DataContext at designtime vs runtime.

Why do we have to add "d:DataContext" while we already have set the "DataContext" ? Why Microsoft introduced DesignTime attributes (code that we have to add, a little bit complex) when it could already be determined automatically by itself using "DataContext" attribute. The only utility that I could see is for a DataContext set in code at RunTime. Otherwise Microsoft could use the DataContext and find the "Shape" of the data like it does with d:DataContext.

What I don't understand properly ? What I'm missing ?

A: 

As yo noted yourself: In many projects/approaches the DataContext will be set dynamically at runtime. So you couldn't know anything about the DataContext at designtime..

SwissCoder
I agree. The problem is that Microsoft could use the DataContext when available and they don't. The d:DataContext should be an option to overwrite the DataContext when needed.Why not using the DataContext when available ???