I am working on a project where i have child project which is referencing the library project.
In my Library project(Phone class library) how do i create ResourceDictionary.xaml where i need to add some styles and use it in xaml files and as well as .cs files.
I need to access styles in ResourceDictionary.xaml in my xaml files as well as .cs files how to do it ?
Create a folder as Generic
in the root folder and have your resource files there...
To access it in XAML
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
or
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/AssembleName;component/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
To access it in .cs
new URI(pack://application:,,,/AssembleName;component/Generic.xaml)
OK, Finally i solved it myself. here is how i solved it.
When you create Phone Class Library Project
you will not the ResourceDictionary.xaml by default
, so what create a xaml page,like how you create a normal xaml file.
Right click on solution ->Add New Item ->Windows Phone Portrait Page.
Now remove the .cs file that is created, add in the .XAML file add your style which is within ResourceDictionary
tag.
The above is all done in Library project.
Now in the child app:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="LibraryResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
suppose you have a style defined in ResourceDictionary as MainScreenButtonStyle you can set in this way
button.Style = (Style)Application.Current.Resources["MainScreenButtonStyle"] as Style;