This utility library lets you easily define your resource values to later be generated as a WPF resource dictionary.
<?xml version="1.0" encoding="utf-8" ?>
<DataValues>
<Colors>
<HexColor Name="ColorRed">#FF0000</HexColor>
<RgbaColor Name="AnotherColorRed">255,0,0</RgbaColor>
<RgbaColor Name="AnotherColorRedWithAlpha">255,0,0,32</RgbaColor>
</Colors>
<Margins>
<Margin>8</Margin>
</Margins>
<FontSizes>
<FontSize>12</FontSize>
</FontSizes>
<Strings>
<String Name="AcceptText">Accept now</String>
<String Name="DescriptionText">
This is some
multi-line description
</String>
</Strings>
</DataValues><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<String
xmlns="clr-namespace:System;assembly=mscorlib"
x:Key="AcceptText"
xml:space="preserve">Accept now</String>
<String
xmlns="clr-namespace:System;assembly=mscorlib"
x:Key="DescriptionText"
xml:space="preserve">
This is some
multi-line description
</String>
<Thickness x:Key="MGN-8">8</Thickness>
<Thickness x:Key="MGN-8-L">8,0,0,0</Thickness>
<Thickness x:Key="MGN-8-T">0,8,0,0</Thickness>
<Thickness x:Key="MGN-8-LT">8,8,0,0</Thickness>
<Thickness x:Key="MGN-8-R">0,0,8,0</Thickness>
<Thickness x:Key="MGN-8-LR">8,0,8,0</Thickness>
<Thickness x:Key="MGN-8-TR">0,8,8,0</Thickness>
<Thickness x:Key="MGN-8-LTR">8,8,8,0</Thickness>
<Thickness x:Key="MGN-8-B">0,0,0,8</Thickness>
<Thickness x:Key="MGN-8-LB">8,0,0,8</Thickness>
<Thickness x:Key="MGN-8-TB">0,8,0,8</Thickness>
<Thickness x:Key="MGN-8-LTB">8,8,0,8</Thickness>
<Thickness x:Key="MGN-8-RB">0,0,8,8</Thickness>
<Thickness x:Key="MGN-8-LRB">8,0,8,8</Thickness>
<Thickness x:Key="MGN-8-TRB">0,8,8,8</Thickness>
<Thickness x:Key="MGN-8-LTRB">8,8,8,8</Thickness>
<Double xmlns="clr-namespace:System;assembly=mscorlib" x:Key="FNT-12">12</Double>
<Color x:Key="ColorRed">#FF0000</Color>
<SolidColorBrush x:Key="ColorRedBrush" Color="{StaticResource ColorRed}" />
<Color x:Key="AnotherColorRed">#FFFF0000</Color>
<SolidColorBrush x:Key="AnotherColorRedBrush" Color="{StaticResource AnotherColorRed}" />
<Color x:Key="AnotherColorRedWithAlpha">#20FF0000</Color>
<SolidColorBrush x:Key="AnotherColorRedWithAlphaBrush" Color="{StaticResource AnotherColorRedWithAlpha}" />
</ResourceDictionary>- Generating Strings
- Generating Margins:
Thicknessobject that can be used for bothMarginandPaddingproperties - Generating FontSizes: Regular
doublevalue that can be used in multiple places, but prefixes make it more expressive - Generating Colors: a
Colorand aSolidColorBrushobjects for various places and animations
- Install the nuget package in your project
- Open your
.csprojfile and utilize this code:
<ItemGroup>
<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
<OptionsType>Global</OptionsType>
<InputFilePath>YourInputFile.xml</InputFilePath>
<OutputFilePath>OutputFile.g.xaml</OutputFilePath>
</WpfUtilityTaskOptions>
</ItemGroup>
<UsingTask AssemblyFile="$(TargetDir)\PsdUtilities.Wpf.MsBuild.dll" TaskFactory="TaskHostFactory" TaskName="WpfUtilityTask" />
<Target Name="WpfUtilityTaskRun" BeforeTargets="Build">
<WpfUtilityTask Parameters="@(WpfUtilityTaskOptions)" />
</Target>Using this library will require you to have the library compiled alongside your main application. Otherwise, modify the 'AssemblyFile' property in the 'UsingTask' element to the correct destination of the DLL library.
For now, there are 4 configuration categories you can modify:
Definition in the .csproj:
<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
<OptionsType>Global</OptionsType>
<!--Properties-->
</WpfUtilityTaskOptions>- [String] InputFilePath: The input data file. Must exist.
- [String] OutputFilePath: The input data file. Gets replaced after each compilation.
Definition in the .csproj:
<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
<OptionsType>Colors</OptionsType>
<!--Properties-->
</WpfUtilityTaskOptions>- [Bool] UseDynamicResource: Whether to use
{DynamicResource ...}over{StaticResource ...}for theSolidColorBrush. - [Bool] ConvertValueToUpperCase: Converts the output
Hexvalue toUPPERCASE. - [Bool] ConvertValueToLowerCase: Converts the output
Hexvalue tolowercase. - [String] SolidColorBrushNameTemplate: The
x:Keytemplate for theSolidColorBrush. Default value is{Color}Brush.{Color}is a required content. - [String] NamePrefix: Prefix for the color name. Empty by default. (Use example: CLR-. Output: CLR-MyColor)
Definition in the .csproj:
<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
<OptionsType>Margins</OptionsType>
<!--Properties-->
</WpfUtilityTaskOptions>- [String] NamePrefix: Prefix for the margin name.
MGN-by default.
Definition in the .csproj:
<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
<OptionsType>FontSizes</OptionsType>
<!--Properties-->
</WpfUtilityTaskOptions>- [String] NamePrefix: Prefix for the margin name.
FNT-by default.
Definition in the .csproj:
<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
<OptionsType>FontSizes</OptionsType>
<!--Properties-->
</WpfUtilityTaskOptions>- [String] NamePrefix: Prefix for the margin name. Empty by default.