[英]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>
為此,您必須使用多文件模板。 像這樣做:
WindowTemplate.DotSettings
的文本文件中。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"><Window x:Class="$Namespace$.$Class$"
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$"
mc:Ignorable="d"
Title="$Class$" Height="450" Width="800">
<Grid>

</Grid>
</Window></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"><RelativeConfig File="$NAME$.xaml.cs" /></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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace $Namespace$
{
/// <summary>
/// Interaction logic for $Class$.xaml
/// </summary>
public partial class $Class$ : Window
{
public $Class$()
{
InitializeComponent();
}
}
}
</s:String></wpf:ResourceDictionary>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.