Overriding PhoneAccentColor doesn't work - windows-phone-7

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.

Related

Xamarin Forms Global Styles Universal Windows Platform

I'm currently working on a Xamarin.Forms application and am specifically applying styles. I've seen examples of global styles placed in the App.xaml file of the desired platform project and was under the impression that you could reference the globally declared styles with a DynamicResourcereference such as below:
in UWP App.xaml
<Application
<Application.Resources>
<ResourceDictionary>
<Style x:Key="myLabel" TargetType="TextBlock">
<Setter Property="Foreground" Value="Purple" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Then in Login.xaml in the Portable Project
<Label Text="hey hey im purple" Style="{DynamicResource myLabel}" />
I'm under the impression that this text should be purple, however it is not. I can style the Label using a ResourceDictionary defined within the page that it is used, however I cannot use it in global.
The interesting thing is that if I declare an implicit global style, it works:
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Purple" />
</Style>
It's when I try explicit global styles with x:Key="myVariable" that it doesnt work.
tldr; global explicit styles are not working for me (but global implicit styles are working)
Any ideas Stack Community? Thanks!
You should define this in your common project's app.xaml instead of define this in UWP app.xaml.
I see that works by myself.

Windows Phone Application Resources

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" ?

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>

Resources