How to set a XAML as Embedded Resource (instead of Page) in Visual Studio Item Template?

Viewed 53

Visual Studio (2019 - have not tested on other versions) seems to be forcing any .xaml file added from a Visual Studio Item Template to have its Build Action set to Page, regardless of the template's settings. For instance:

  <TemplateContent>
    <References />
    <ProjectItem ReplaceParameters="true" ItemType="EmbeddedResource" CustomTool="" TargetFileName="$fileinputname$.xaml">Page1.xaml</ProjectItem>
    <ProjectItem ReplaceParameters="true" ItemType="EmbeddedResource" CustomTool="" TargetFileName="$fileinputname$.cs">Page1.xaml</ProjectItem>
  </TemplateContent>

That just adds the same XAML file twice to demonstrate that when added as a .cs file everything works as intended with the build action corresponds to the ItemType as desired. However, when added with a .xaml extension, the build type is forced to Page - overriding the ItemType specification.

Is this intended behavior of the Visual Studio Item Template parser, and if so is there any way to override it? All I need is for the XAML file to be correctly seen as a XAML file (to enable the designer) with its build action set to Embedded Resource.

0 Answers
Related