我正在尝试将资源字典添加到我的silverlight-4应用程序中(建议在http://msdn.microsoft.com/en-us/magazine/dd419663.aspx文章的“将视图应用到ViewModel”一章中)。
第一个问题:我的MainPage中看不到任何资源。我是否正确理解了需要手动将资源字典添加到Silverlight应用程序中?
第二个:当我这样做时,在Dictionary1.xaml文件中
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib">
<DataTemplate DataType="{x:Type vm:MyViewModel}">
<vw:MyView />
</DataTemplate>
</ResourceDictionary>我收到一个错误:无法解析符号'DataType'...
有没有什么好主意去做呢?
发布于 2010-07-12 13:48:20
广告1: MainPage有一个ResourceDictionary。在xaml中向其添加元素,如下所示:
<MainPage>
<MainPage.ResourceDictionary>
<DataTemplate>
<vw:MyView />
</DataTemplate>
</MainPage.ResourceDictionary>
...您可以使用ResourceDictionary的Source和MergedDictionaries属性将MainPage.ResourceDictionary添加到ResourceDictionary:
<MainPage>
<MainPage.ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</MainPage.ResourceDictionary>
...广告2: DataTemplate在Silverlight框架中没有属性DataType。:-(
发布于 2010-07-12 06:25:39
如果要在ResourceDictionary中使用,还需要在DataTemplate中添加一个x:键。
https://stackoverflow.com/questions/3224567
复制相似问题