Windows phone 7 Windows Phone 7:找不到全局资源
我正在尝试使用全局资源字典,但在尝试使用它包含的样式时出错。在我的app.xaml中,我有:Windows phone 7 Windows Phone 7:找不到全局资源,windows-phone-7,datatemplate,styles,resourcedictionary,windows-phone,Windows Phone 7,Datatemplate,Styles,Resourcedictionary,Windows Phone,我正在尝试使用全局资源字典,但在尝试使用它包含的样式时出错。在我的app.xaml中,我有: <Application.Resources> <ViewModel:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> <ResourceDictionary x:Key="dict1">
<Application.Resources>
<ViewModel:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
<ResourceDictionary x:Key="dict1">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/ListBox.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
在/Themes/ListBox.xaml中,我有:
<Style x:Key="CategoryListTemplate" TargetType="ListBox">
<Setter Property="Background" Value="Transparent" />
<Setter Property="SelectionMode" Value="Extended" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="2" />
<Setter Property="Template">
....
....
我正在尝试设置以下样式:
<ListBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" x:Name="lstCategories" SelectionMode="Extended" Style="{StaticResource CategoryListTemplate}" ...
请参阅
手机似乎不支持以这种方式合并词典。我用App.xaml.cs中的以下内容解决了这个问题:
var dictionaries = Resources.MergedDictionaries;
dictionaries.Clear();
var dicts = new[]{
"/ChickenPing.Mobile;component/Themes/ThemeResources.xaml",
"/ChickenPing.Mobile;component/Themes/generic.xaml",
"/ChickenPing.Mobile;component/Themes/ListBox.xaml",
"/ChickenPing.Mobile;component/Themes/Rating.xaml",
"/ChickenPing.Mobile;component/Themes/CheckBox.xaml",
};
foreach (var dict in dicts) {
var themeStyles = new ResourceDictionary {Source = new Uri(dict, UriKind.Relative)};
dictionaries.Add(themeStyles);
}