Windows Phone Application Resources - windows-phone-7

I've added resource to App.xaml like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
But when I start the application it crashed with unspecified error.
And thoughts?
Thanks!

ur code seems to be alright.
in ur code--->
<ResourceDictionary Source="Generic.xaml"/>
might be there is some path error "Generic.xaml" , are u sure this Generic.xaml file is in ur root directory. or it should be "someFolder/Generic.xaml" ?

Related

Xamarin Forms, "Invalid syntax for a hexadecimal numeric entity reference" error inside App.xaml when importing Icon

the font.otf is imported correctly and placed inside the correct folder because the font works on letters but importing an icon from the otf file does not work because of the syntax error. Entering &#x before the icon code "uf1ea" is what caused the error but it's important for finding the icon otherwise it would just display "uf1ea" on the emulator and not the actual icon.
here's a snippet of the code i wrote in app.xaml :
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="testingfont.App">
<Application.Resources>
<ResourceDictionary>
<x:String x:Key="Newspaper">&#xuf1ea;</x:String>
</ResourceDictionary>
</Application.Resources>
</Application>
You don't need to add a u in your icon code, just use it like below:
<x:String x:Key="Newspaper"></x:String>
After adding the icon codes in a new class, this worked for me:
<Label Text=""/>

WP7, WP8 How to set several ResourceDictionaries to use custom FontFamilies

I want to set custom fonts for some controls, so if I set a font inside the only one ResourceDictionary and use it in styles then everything works just fine. But this approach is not fine for me, because I need to have font declarations in a separate dictionary then styles that are using them.
In App.xaml I have made several Resource Dictionaries
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/ResourceAgencyDictionary.xaml"/>
<ResourceDictionary Source="Resources/ResourceCommonDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
....
</Application>
In ResourceAgencyDictionary.xaml I have MyFontFamilyNormal declaration
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FontFamily x:Key="MyFontFamilyNormal">/GBAgencyCommon;component/Fonts/Fonts.zip#Gotham Book</FontFamily>
.....
</ResourceDictionary>
In ResourceCommonDictionary.xaml I want to use that font family (MyFontFamilyNormal):
<ResourceDictionary ...>
<Style x:Key="MyTextBlockValueStyle" BasedOn="{StaticResource PhoneTextBlockBase}" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource MyFontFamilyNormal}"/>
....
</Style>
</ResourceDictionary>
The project compiles but I get a runtime error
System.Windows.Markup.XamlParseException occurred
_HResult=-2146233087
_message=Cannot find a Resource with the Name/Key MyFontFamilyNormal
Does anyone know how can I fix that?
Sorry guys, searched the solution a lot in Internet and just found it.
The solution was simple (I've tried it but with wrong path to file and didn't notice that it was the right direction)
so in App.xaml
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/ResourceCommonDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
....
</Application>
the ResourceAgencyDictionary.xaml is the same
in ResourceCommonDictionary.xaml
<ResourceDictionary ...>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceAgencyDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="MyTextBlockValueStyle" BasedOn="{StaticResource PhoneTextBlockBase}" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource MyFontFamilyNormal}"/>
....
</Style>
</ResourceDictionary>
NOTE: Source="ResourceAgencyDictionary.xaml" because this file is in the same folder as ResourceCommonDictionary.xaml

I get a XamlParseException when i try to load a merged ResourceDictionary filled with DataTemplates

In my Windows Phone 7.5 application i want to have a merged ResourceDictionary filled with DataTemplates. To achieve this, i created a file called "DataTemplates.xaml" and filled it with DataTemplates like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="ItemTemplate">
<!-- xaml -->
</DataTemplate>
<DataTemplate x:Key="GroupHeaderTemplate">
<!-- xaml -->
</DataTemplate>
<DataTemplate x:Key="GroupItemTemplate" >
<!-- xaml -->
</DataTemplate>
</ResourceDictionary>
In page where i want to use that DataTemplates i wrote this code:
<phone:PhoneApplicationPage.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/myAssemblyName;component/Resources/DataTemplates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</phone:PhoneApplicationPage.Resources>
But, when i debug and try to navigate to the page that contains the ResourceDictionary i got a XamlParseException: Failed to assign to property 'System.Windows.ResourceDictionary.Source'
How can i do? :( Thank you!
Ok, i spent about 20 minutes to write question and after rereading it i found solution, so i answer myself: i accidentally wrote the namespace of solution instead of its assembly name! That's all, now the ResourceDictionary loads properly :)

Referencing a merged resource dictionary in windows phone seven failing

I am currently building a WP7 app using the MVVMLight framework. I would like to add a resource dictionary to my app.xaml, however when I do it fails. Here is a snipit from the app.xaml
<Application.Resources>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
<!--Merged Resource Dictionaries-->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="View/StyleResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Because I am using a ViewModelLocator that has a key, I get an error warning me that I can not mix resources with and without keys. After adding a key to my resource dictionary It looks like the following:
<ResourceDictionary x:Key="resourceDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="View/StyleResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
In the resource dictionary I have a style with the key "TitleTemplate". In either case when I try to reference the resource dictionary from one of my views it fails. Sample code from my view is bellow:
<TextBlock Name="TB_ContactNameLabel"
Text="contact"
Style="{StaticResource TitleTemplate}"/>
The designer immediately gives me the error "The resource 'TitleTemplate' could not be resolved". If I reference the key of the resourced dictionary (ie: resourceDictionary) no error is thrown but it doesn't do anything obviously. Finally if I add the resourceDictionary directly to the page in its resources, instead of the app.xaml everything works fine. I do not want to have to add it to each view I plan to use. Am I missing something here?
Your application resources should look like the following:
<Application.Resources>
<!--Global View Model Locator-->
<!--Merged Resource Dictionaries-->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="View/StyleResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
</Application.Resources>

Overriding PhoneAccentColor doesn't work

I just want to customize the PhoneAccentColor within my application, but it doesn't seem to work.
I made App Resources looking like:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Utils/Converters.xaml"/>
<ResourceDictionary Source="Resources/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<ViewModels:ViewModelLocator x:Key="ViewModelLocator" d:IsDataSource="True" />
<Resources:ResourcesWrapper x:Key="ResWrapper" d:IsDataSource="True" />
</ResourceDictionary>
</Application.Resources>
And in the Styles.xaml I redefined the PhoneAccentColor like this:
<Color x:Key="PhoneAccentColor">#FFFF0000</Color>
But for any reason the default phone accent color is still used.
For example I'm using the PerformanceProgressBar from the toolkit which still uses the default color instead of the definied red.
Is there anything I missed?
Solved: Seems like you also have to override within the Styles.xaml.

Resources