C# 雷沙珀。如何添加xaml模板

C# 雷沙珀。如何添加xaml模板,c#,wpf,visual-studio,xaml,C#,Wpf,Visual Studio,Xaml,如何添加扩展名为.xaml的Resharper模板? 例如,我试图添加一个Window.xaml,问题就在这一行 为此,必须使用多文件模板。这样做: 将本文末尾的代码复制到名为WindowTemplate.DotSettings的文本文件中 通过扩展打开ReSharper模板资源管理器→ 再竖琴→ 工具→ 模板资源管理器 打开“文件模板”选项卡并导入文件WindowTemplate.DotSettings 您应该会看到一个名为“自定义窗口”的模板。如果您对代码感兴趣,可以将其打开。您还可以在将“

如何添加扩展名为.xaml的Resharper模板? 例如,我试图添加一个Window.xaml,问题就在这一行
为此,必须使用多文件模板。这样做:

  • 将本文末尾的代码复制到名为
    WindowTemplate.DotSettings
    的文本文件中
  • 通过扩展打开ReSharper模板资源管理器→ 再竖琴→ 工具→ 模板资源管理器
  • 打开“文件模板”选项卡并导入文件
    WindowTemplate.DotSettings
  • 您应该会看到一个名为“自定义窗口”的模板。如果您对代码感兴趣,可以将其打开。您还可以在将“模板资源管理器”中的图层设置为“智能”时将模板添加到“快速列表”

    在解决方案资源管理器中使用
    Alt
    +
    Insert
    并打开“更多…”时,将出现模板。选择它并输入文件名。现在代码生成完成了

    但是,您将无法编译它,出现以下错误:
    CS0103:当前上下文中不存在名称“InitializeComponent”
    。您必须为每个文件手动解决此问题,方法是打开
    *.csproj
    文件并查找以下代码:

    <AdditionalFiles Include="Demo3.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </AdditionalFiles>
    
    最后但并非最不重要的是,必要的模板代码:

    <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Description/@EntryValue">Custom Window</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Text/@EntryValue">&lt;Window x:Class="$Namespace$.$Class$"&#xD;
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&#xD;
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&#xD;
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"&#xD;
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"&#xD;
        xmlns:local="clr-namespace:$Namespace$"&#xD;
        mc:Ignorable="d"&#xD;
        Title="$Class$" Height="450" Width="800"&gt;&#xD;
    &lt;Grid&gt;&#xD;
    &#xD;
    &lt;/Grid&gt;&#xD;
    &lt;/Window&gt;</s:String>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Reformat/@EntryValue">True</s:Boolean>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/ShortenQualifiedReferences/@EntryValue">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/CustomProperties/=FileName/@EntryIndexedValue">Window</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/CustomProperties/=Extension/@EntryIndexedValue">xaml</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/CustomProperties/=ValidateFileName/@EntryIndexedValue">False</s:String>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Applicability/=File/@EntryIndexedValue">True</s:Boolean>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Scope/=55C906A5BD591341AE313A07A8F303DE/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Scope/=55C906A5BD591341AE313A07A8F303DE/Type/@EntryValue">InAnyXamlProject</s:String>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/Expression/@EntryValue">fileDefaultNamespace()</s:String>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/InitialRange/@EntryValue">-1</s:Int64>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/Order/@EntryValue">0</s:Int64>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/Expression/@EntryValue">getAlphaNumericMainFileNameWithoutExtension()</s:String>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/InitialRange/@EntryValue">-1</s:Int64>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/Order/@EntryValue">1</s:Int64>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/LocationSelectorName/@EntryValue">manual</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/LocationSelectorConfig/@EntryValue">&lt;RelativeConfig File="$NAME$.xaml.cs" /&gt;</s:String>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/Order/@EntryValue">0</s:Int64>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/SectionPlain/Text/@EntryValue">using System;&#xD;
    using System.Collections.Generic;&#xD;
    using System.Linq;&#xD;
    using System.Text;&#xD;
    using System.Threading.Tasks;&#xD;
    using System.Windows;&#xD;
    using System.Windows.Controls;&#xD;
    using System.Windows.Data;&#xD;
    using System.Windows.Documents;&#xD;
    using System.Windows.Input;&#xD;
    using System.Windows.Media;&#xD;
    using System.Windows.Media.Imaging;&#xD;
    using System.Windows.Navigation;&#xD;
    using System.Windows.Shapes;&#xD;
    &#xD;
    namespace $Namespace$&#xD;
    {&#xD;
        /// &lt;summary&gt;&#xD;
        /// Interaction logic for $Class$.xaml&#xD;
        /// &lt;/summary&gt;&#xD;
        public partial class $Class$ : Window&#xD;
        {&#xD;
            public $Class$()&#xD;
            {&#xD;
                InitializeComponent();&#xD;
            }&#xD;
        }&#xD;
    }&#xD;
    </s:String></wpf:ResourceDictionary>
    
    
    真的
    自定义窗口
    窗口x:Class=“$Namespace$.$Class$”和#xD;
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation“
;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml“
;
    xmlns:d=”http://schemas.microsoft.com/expression/blend/2008“
;
    xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006“
;
    xmlns:local=“clr namespace:$namespace$”和#xD;
    mc:Ignorable=“d”和#xD;
    Title=“$Class$”Height=“450”Width=“800”和#xD;
    网格和xD;
    
;
    /网格和xD;
    /窗口
    真的
    真的
    窗口
    xaml
    假的
    真的
    真的
    Inanyxalm项目
    真的
    fileDefaultNamespace()
    -1
    0
    真的
    getAlphaNumericMainFileNameWithoutExtension()
    -1
    1.
    真的
    手册
    RelativeConfig文件=“$NAME$.xaml.cs”/
    0
    使用制度&#除息的;
    使用System.Collections.Generic&#除息的;
    使用System.Linq&#除息的;
    使用系统文本&#除息的;
    使用System.Threading.Tasks&#除息的;
    使用System.Windows&#除息的;
    使用System.Windows.Controls&#除息的;
    使用System.Windows.Data&#除息的;
    使用System.Windows.Documents&#除息的;
    使用System.Windows.Input&#除息的;
    使用System.Windows.Media&#除息的;
    使用System.Windows.Media.Imaging&#除息的;
    使用System.Windows.Navigation&#除息的;
    使用System.Windows.Shapes&#除息的;
    
;
    名称空间$namespace$
;
    {
;
    ///总结
;
    ///$Class$.xaml
;
    ////总结和#xD;
    公共部分类$class$:窗口和#xD;
    {
;
    公共$Class$()和#xD;
    {
;
    初始化组件()
;
    }
;
    }
;
    }
;
    
    您能更详细地解释一下您的问题吗?是否只需输入一个字符串?您可以使用这样的变量来实现这一点:
    我喜欢使用热键,在ReSharper-ctrl+Insert中,让我使用各种模板来自动创建类、接口等,但没有任何用于创建Windows1.xaml表单的模板。您的答案-谢谢,$Class$set宏“当前无扩展名文件名”
    
    <Page Include="Demo3.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </Page>
    
    <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Description/@EntryValue">Custom Window</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Text/@EntryValue">&lt;Window x:Class="$Namespace$.$Class$"&#xD;
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&#xD;
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&#xD;
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"&#xD;
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"&#xD;
        xmlns:local="clr-namespace:$Namespace$"&#xD;
        mc:Ignorable="d"&#xD;
        Title="$Class$" Height="450" Width="800"&gt;&#xD;
    &lt;Grid&gt;&#xD;
    &#xD;
    &lt;/Grid&gt;&#xD;
    &lt;/Window&gt;</s:String>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Reformat/@EntryValue">True</s:Boolean>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/ShortenQualifiedReferences/@EntryValue">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/CustomProperties/=FileName/@EntryIndexedValue">Window</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/CustomProperties/=Extension/@EntryIndexedValue">xaml</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/CustomProperties/=ValidateFileName/@EntryIndexedValue">False</s:String>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Applicability/=File/@EntryIndexedValue">True</s:Boolean>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Scope/=55C906A5BD591341AE313A07A8F303DE/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Scope/=55C906A5BD591341AE313A07A8F303DE/Type/@EntryValue">InAnyXamlProject</s:String>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/Expression/@EntryValue">fileDefaultNamespace()</s:String>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/InitialRange/@EntryValue">-1</s:Int64>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Namespace/Order/@EntryValue">0</s:Int64>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/Expression/@EntryValue">getAlphaNumericMainFileNameWithoutExtension()</s:String>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/InitialRange/@EntryValue">-1</s:Int64>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Field/=Class/Order/@EntryValue">1</s:Int64>
        <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/@KeyIndexDefined">True</s:Boolean>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/LocationSelectorName/@EntryValue">manual</s:String>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/LocationSelectorConfig/@EntryValue">&lt;RelativeConfig File="$NAME$.xaml.cs" /&gt;</s:String>
        <s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/Order/@EntryValue">0</s:Int64>
        <s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0CB2F5C22C4A274F8D1425E1F1DA05CF/Section/=60769A869101874889D7DC3F51C8EEA7/SectionPlain/Text/@EntryValue">using System;&#xD;
    using System.Collections.Generic;&#xD;
    using System.Linq;&#xD;
    using System.Text;&#xD;
    using System.Threading.Tasks;&#xD;
    using System.Windows;&#xD;
    using System.Windows.Controls;&#xD;
    using System.Windows.Data;&#xD;
    using System.Windows.Documents;&#xD;
    using System.Windows.Input;&#xD;
    using System.Windows.Media;&#xD;
    using System.Windows.Media.Imaging;&#xD;
    using System.Windows.Navigation;&#xD;
    using System.Windows.Shapes;&#xD;
    &#xD;
    namespace $Namespace$&#xD;
    {&#xD;
        /// &lt;summary&gt;&#xD;
        /// Interaction logic for $Class$.xaml&#xD;
        /// &lt;/summary&gt;&#xD;
        public partial class $Class$ : Window&#xD;
        {&#xD;
            public $Class$()&#xD;
            {&#xD;
                InitializeComponent();&#xD;
            }&#xD;
        }&#xD;
    }&#xD;
    </s:String></wpf:ResourceDictionary>