Compartir a través de


Move, copy, or export a resource

Because resources can be defined in different scopes in your Blend para Visual Studio 2012 application, it might become necessary to move an existing resource if you want to make the resource available in a wider or more limited scope in your application. For example, if you define an object-level resource but want to make it available to you whole application, you could move the resource to the App.xaml file. If you want to export a resource to another application, you could move the resource to an external resource dictionary.

Nota de precauciónPrecaución

Some resources (such as styles or control templates) might use additional resources (such as brush or color resources). When you move or copy resources, Blend will move the additional resources if their key names cannot be resolved in the scope of the destination. If resources already in the destination have duplicate names, a dialog box is displayed to give you the option to overwrite the existing resources, create new resources with different names and update the references, or use the existing resources.

Note that if resources reference additional system resources, the system resources are not copied because they are always available.

Exporting a resource

Resources can be exported by putting them in a resource dictionary file that can be added as an item to another project.

To export a resource

  1. If you do not have a resource dictionary in which you want to export the resource, click Create new resource dictionary JJ170411.35c35d1d-ac87-42f7-adc4-d620dbe60297(es-es,VS.110).png in the Resources panel.

    The New Item dialog box appears.

  2. Enter a name for your resource dictionary and then click OK.

    The new resource dictionary is added as a new file in the Projects panel, and listed as a container for resources in the Resources panel.

    You can now use the next procedure 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 move a resource

  1. In the Resources panel, locate the resource that you want to move by expanding the resource container nodes.

    • Application-level resources are listed under the App.xaml node.

    • Dictionary-level resources are listed under the node that is identified by the name of the resource dictionary file.

    • Document-level resources are listed under the node that is identified by the name of the root element in your document (for example, expand Window1.xaml, and then expand Window).

    • Object-level resources are listed under the node that is identified by the name of the object.

  2. Using your mouse, click the resource that you want to move, and then drag it to the new location. If you want to export the resource to another project, move the resource to a dictionary file.

To copy a resource

  1. In the Resources panel, locate the resource that you want to move by expanding the resource container nodes.

    • Application-level resources are listed under the App.xaml node.

    • Dictionary-level resources are listed under the node that is identified by the name of the resource dictionary file.

    • Document-level resources are listed under the node that is identified by the name of the root element in your document (for example, expand Window1.xaml, and then expand Window).

    • Object-level resources are listed under the node that is identified by the name of the object.

  2. Right-click the resource name and then click Copy.

  3. Right-click the location where you want to copy the resource and then click Paste.

    Nota de precauciónPrecaución

    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, rename the original or the copied resource after you copy. For instructions on renaming a resource, see Rename a resource.