Reputation: 185
How to add in the Resharper template with .xaml extension?
For example, I am trying to add a Window.xaml and the problem is in this line
<Window x:Class="ADONET_Samples.UserControls.Window1"
how to put in "Window1" the name of your XAML form.
<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>
Upvotes: 0
Views: 294
Reputation: 5384
For this, you have to use a multifile template. Do it like this:
WindowTemplate.DotSettings
.WindowTemplate.DotSettings
.You should see a template called Custom Window. If you're interested in the code, you can open it.You can also add the template to the quicklist when setting the layer within Templates Explorer to Smart.
When using Alt
+ Insert
in Solution Explorer and opening More..., there will be the template. Choose it an enter a name for the file. Now the code generation is done.
However, you won't be able to compile it with the following error: CS0103: The name 'InitializeComponent' does not exist in the current context
. You have to solve this manually for every file by opening the *.csproj
file and looking for the following code:
<AdditionalFiles Include="Demo3.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</AdditionalFiles>
Replace it with (notice Page
instead of AdditionalFile
):
<Page Include="Demo3.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Last but not least, the necessary template code:
<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>
Upvotes: 2