1

I am facing issue with binding and I am following this example : http://listboxwthcheckboxes.codeplex.com/

Now the simple problem of the moment is that, the example has binded listbox succesfully to ViewModelSampleData.xaml(In the sampleData directory). But this binding only appears when I am viewing this in design view. When I run the app a new runtime data appears that is generated with code. This is counter productive in my case. My app can simple show the xaml data. I know it has to do something with these lines.

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignData SampleData/ViewModelSampleData.xaml}"

Can you explain what can I do correct this? And give me a link or two that helps me understand what colons are used for and how can replace make this DataContext same that is used on Runtime.

Pinser
  • 1,898
  • 3
  • 29
  • 43

2 Answers2

2

The d: namespace is only valid for design mode.

For the runtime mode you have to bind the DataContext without the d::

 DataContext="{Binding ...}"
thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110
  • DataContext="{Binding SampleData/ViewModelSampleData.xaml}" This gives error. This is done in root tag of MainPage.xaml. – Pinser Dec 06 '12 at 13:53
  • Can you add a few links that direct me to understand what is happening. I have followed read links but out of luck. – Pinser Dec 06 '12 at 13:58
  • I am not sure if you can bind to the sample data directly. You could deserialize the sample data into an object and then bind to that object in code behind: DataContext = myDeserializedObject. – thumbmunkeys Dec 06 '12 at 14:38
  • I am sure this is possible, but cant get to how? – Pinser Dec 06 '12 at 17:30
0

As you are a beginner, I suggest you to follow the straight forward approach for the data binding, instead of complex MVVM approach.

Check this link for the Binding Data to ListBox through Code

And this ListBox databinding also

nkchandra
  • 5,585
  • 2
  • 30
  • 45
  • Thankyou for these links but I have gone through those. I really want to bind data to XAML objects at the moment. Appreciate your help! – Pinser Dec 06 '12 at 14:13
  • 1
    I could not disagree more. If he is a beginner, let him learn correctly from the beginning. Advising him to introduce architectural debt because he is new isn't a wise approach in my mind. He doesn't have to code it perfectly, but he should be encouraged to do it right, not wrong. And without MVVM, it's wrong. – Jerry Nixon Dec 07 '12 at 19:59
  • 1
    @JerryNixon-MSFT I agree. +1 for your comment :) – nkchandra Dec 07 '12 at 21:40