簡體   English   中英

銳化。 如何添加 xaml 模板

[英]Resharper. How to add xaml template

如何添加帶有.xaml 擴展名的 Resharper 模板? 例如,我正在嘗試添加 Window.xaml 問題出在這一行<Window x:Class="ADONET_Samples.UserControls.Window1" how to put in "Window1" the name of your Z8CBFD5 form.BBBFD56579569FBD43DDDD8

<Window x:Class="ADONET_Samples.UserControls.Window1"
    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:ADONET_Samples.UserControls"
    mc:Ignorable="d"
    Title="Window1" Height="450" Width="800">
<Grid>

</Grid>

為此,您必須使用多文件模板。 像這樣做:

  1. 將本文末尾的代碼復制到名為WindowTemplate.DotSettings的文本文件中。
  2. 通過Extensions → ReSharper → Tools → Templates Explorer...打開 ReSharper Templates Explorer...。
  3. 打開選項卡文件模板並導入文件WindowTemplate.DotSettings

您應該會看到一個名為Custom Window的模板。 如果您對代碼感興趣,可以打開它。您也可以在 Templates Explorer 中將圖層設置為Smart時將模板添加到快速列表中。

在解決方案資源管理器中使用Alt + Insert並打開More...時,會有模板。 選擇它並輸入文件的名稱。 現在代碼生成完成了。

但是,您將無法編譯它並出現以下錯誤: CS0103: The name 'InitializeComponent' does not exist in the current context 您必須通過打開*.csproj文件並查找以下代碼為每個文件手動解決此問題:

<AdditionalFiles Include="Demo3.xaml">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
</AdditionalFiles>

將其替換為(注意Page而不是AdditionalFile ):

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM