Creating Addins for XamlPadX

I got a few queries after releasing XamlPadX v3 regarding creating addins for the tool. So here is a small post on it. :)

Create a customControlLibrary project. Add a reference to the AddInView dll present in the XamlPadX folder which is located in the program files folder. Also add a reference to the 3.5 System.Addin dll.

Now in the xaml file change the UserControl Tag into AddInAddInView

<f:AddInAddInView x:Class="customaddin.UserControl1"

xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"

xmlns:f="https://foo"

Height="200" Width="200">

<Grid>

<Rectangle Fill="red" Height="100" Width="100"/>

</Grid>

</f:AddInAddInView>

the namespace is exposed as https://foo/ in the AddInView.dll :) 

 Now for the code behind

    [AddIn("MyAddin", Description="This is my addin", Publisher="MS", Version="1.0.0.0")]

    public partial class UserControl1: AddInViews.AddInAddInView

The usercontrol extends from the AddInAddInView class. Also creating an AddIn attribute makes it readable in the addin dialog. The AddIn attribute takes (AddinName, Description, Publisher, Version).

You will also need to override 2 functions. SendSignal(String) and Initialize(AddInHostView)

The SendSignal just passes a string ("Displaying Addin: Name") from the host to the Addin. In the colorPallete Addin, the function opens a MessageDialog. The function is a demo of host-addin communication.

The Initialize function passes the host object to the addin. The host object provides access to 3 functions.

ChangeAppBackground - changes the background of the xamlpadX app ( you can see this working if you click the last button in the colorpallete addin)

TextBoxCaretIndex - caret index in the editing textbox of the xamlpadX tool. This is helpful if you want to insert some text

textBoxContents - Content of the editing textbox in the tool. This is a get/set property so you can set the entire content of the textbox.

The final part is the placement of the dll. By default the xamlpadX files are placed in ProgramFiles/XamlPadX. There is an Addins folder. Create a folder for you addin and place your dll in this folder (do not place the addinview dll..it already exists). Restart XamlPadX and you should see your addin the Addin dialog.

attached is a sample addin project.

Share this post

 

customaddin.zip