开发者

WP7 Silverlight: Data binding with the same XAML at design & runtime

I'd like to use the same data at design and runtime in my WP7 appli开发者_C百科cation. The relevant part of the XAML looks like this:

<phone:PhoneApplicationPage ...
  d:DataContext="{d:DesignData Source=data.xaml}"
  DataContext="{Binding Source=???}"

This way I can see the data at design time. Is there a way to use the same data at runtime?


Was not aware of the existence of d:DataContext. I dare to say:

<phone:PhoneApplicationPage ...
d:DataContext="{d:DesignData Source=data.xaml}"
DataContext="{Binding Source=data.xaml}"

--- Edit added -------------------

Well... checking here and there found that, as expected, "DesignData" is not the same as "Binding" (I was misreading this, sorry). "DesignData" has the ability to instance, at design time, an object based on a xml file and this has no effect at runtime. The Binding we are try to build will never work, as its purpose is to use already instanced objects.

When you run the default template for panorama applications it instances its own data (check the code for MainViewModel.cs)... and that's why it shows is different from that in the xml file. All you have to do is, manually, open the xml in the "LoadData" method and load the file data so you can display the same at runtime and design time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜