Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to write style in another xaml file and attribute the object in another xaml page?
Posted
Updated 18-Nov-13 10:25am
v2

1 solution

Do you mean you want to put your xaml styles in one file and use them in another? yes.

you can do that. You can create a ResourceDictionary to hold your styles and be used by many other files. you just need to include it as a resource in each file or you can add it to the Application.Resources in your app.xaml then it will be available to the entire application.

XML
<Application x:Class="myNameSpace.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/SomeDllWithResource;component/Layout/WPFDataGridLayout.xaml" />
                <ResourceDictionary  Source="myResources.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>


once you've created the Resource dictionary you can include it like above for 'myResources.xaml' that line can be put in the resources section of a specific file or in the app.xaml like the example above.
 
Share this answer
 
v2
Comments
[no name] 18-Nov-13 16:43pm    
can you give me example how to include it as a resource?
bowlturner 18-Nov-13 16:50pm    
added to the answer above. does that help?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900