Create, export, or import a resource dictionary
Resources in a resource dictionary can be applied anywhere within your application because resource dictionaries are linked to your project in the App.xaml file. You can package a set of resources into a resource dictionary file and reuse the entire file in another application.
For instructions on how to move existing resources into a resource dictionary, see Move, copy, or export a resource.
To create a resource dictionary
In the Resources panel, click Create new resource dictionary .
The New Item dialog box appears.
Type a name for your resource dictionary, and then click OK.
The new resource dictionary is added as a new file in the Project panel, and listed as a container for resources in the Resources panel.
You can now use the procedures in Move, copy, or export a resource to move resources to the new resource dictionary. Additionally, when you create a new resource, you can select the new resource dictionary in the Define in section of the Create New Resource dialog box.
To export a resource dictionary
- You do not need to do anything to export a resource dictionary because a resource dictionary is a separate .xaml file that you can import into another project.
To import a resource dictionary
In the Project panel or on the Project menu, do one of the following:
Click Add Existing Item to copy the resource dictionary into your project folder.
The Add Existing Item window appears.
Click Link to Existing Item to link to a resource dictionary without copying it into your project folder.
The Link to Existing Item window appears.
Browse to your resource dictionary file, and then click Open.
The new resource dictionary is added as a new file in the Project panel, and is listed as a container for resources in the Resources panel.
주의 If two different resources in the same project have the same name, you might get unexpected results on the artboard if the wrong resource is applied to a control. To avoid this problem, check your resource dictionaries for duplicate resource names, and rename resources as necessary.
For instructions on renaming a resource, see Rename a resource.
To remove a resource dictionary
Check for any controls whose properties use the resources in the dictionary that you want to remove. If there are resources that you want to save, drag them to a different location in the Resources panel, such as a different resource dictionary, or the App.xaml file.
In the Resources panel, expand the App.xaml node, right-click the link to the resource dictionary, and then click Delete.
The Deleting Link dialog box appears. Click Yes to continue removing the resource dictionary link, or click No to cancel.
In the Project panel, right-click the resource dictionary that you want to remove, and then do one of the following:
Click Remove from project to remove the resource dictionary without deleting it from your project folder.
Click Delete to delete the resource dictionary file from your project folder.
The Confirm File Remove dialog box appears. Click Yes to removing the resource dictionary.
The resource dictionary is removed from your project.