Skip to content

A utility library that extremely conveniently generates XAML values based on provided options using MSBuild Tasks.

License

Notifications You must be signed in to change notification settings

psdlex/PsdUtilities.Wpf.MsBuild

Repository files navigation

PsdUtilities.Wpf.MsBuild

This utility library lets you easily define your resource values to later be generated as a WPF resource dictionary.

Example of XML file Definition

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

And this generates something like this:

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

Feature List

  • Generating Strings
  • Generating Margins: Thickness object that can be used for both Margin and Padding properties
  • Generating FontSizes: Regular double value that can be used in multiple places, but prefixes make it more expressive
  • Generating Colors: a Color and a SolidColorBrush objects for various places and animations

How to setup in Your Project

  • Install the nuget package in your project
  • Open your .csproj file 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.

Configuration

For now, there are 4 configuration categories you can modify:

Global Options

Definition in the .csproj:

<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
  <OptionsType>Global</OptionsType>
  <!--Properties-->
</WpfUtilityTaskOptions>

Properties:

  • [String] InputFilePath: The input data file. Must exist.
  • [String] OutputFilePath: The input data file. Gets replaced after each compilation.

Colors Options

Definition in the .csproj:

<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
  <OptionsType>Colors</OptionsType>
  <!--Properties-->
</WpfUtilityTaskOptions>

Properties

  • [Bool] UseDynamicResource: Whether to use {DynamicResource ...} over {StaticResource ...} for the SolidColorBrush.
  • [Bool] ConvertValueToUpperCase: Converts the output Hex value to UPPERCASE.
  • [Bool] ConvertValueToLowerCase: Converts the output Hex value to lowercase.
  • [String] SolidColorBrushNameTemplate: The x:Key template for the SolidColorBrush. 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)

Margins Options

Definition in the .csproj:

<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
  <OptionsType>Margins</OptionsType>
  <!--Properties-->
</WpfUtilityTaskOptions>

Properties

  • [String] NamePrefix: Prefix for the margin name. MGN- by default.

FontSizes Options

Definition in the .csproj:

<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
  <OptionsType>FontSizes</OptionsType>
  <!--Properties-->
</WpfUtilityTaskOptions>

Properties

  • [String] NamePrefix: Prefix for the margin name. FNT- by default.

Strings Options

Definition in the .csproj:

<WpfUtilityTaskOptions Include="WpfUtilityTaskOptions">
  <OptionsType>FontSizes</OptionsType>
  <!--Properties-->
</WpfUtilityTaskOptions>

Properties

  • [String] NamePrefix: Prefix for the margin name. Empty by default.

Nuget

https://www.nuget.org/packages/PsdUtilities.Wpf.MsBuild

About

A utility library that extremely conveniently generates XAML values based on provided options using MSBuild Tasks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages