Kine's Info

What I found and what I know about Microsoft Dynamics NAV

Universal WPF hosting addin for NAV v1.1

Hello everybody

Today I am happy that I have managed to finish new version of the Uni WPF addin. Now you are able to catch events of the controls inside NAV and dynamically change properties of the controls. The demo object I have made is creating simple calculator inside the addin (calculator is not fully working, you can just type numbers and clear them), but it is not hard to extend it to fully functional because you need only modify code inside NAV.


This addin is now ready to be used e.g. for creating touch screens for POS and other systems, to display dynamically created buttons, drawings, may be grids, pictures, media (you can easily play some video inside…). All the properties of WPF are used, thus the content is automatically resized if all is set correctly inside the XAML (data binding the controls between each other). Example is this “calculator”:


How it works:

If you bind the addin to BigText variable, you can pass XML into this addin in this format:

    //there is XAML describing the controls which should be added into the addin, the XAML must include correct name spaces
  <Host <attributexxx>="<zzz>" <attributeaaa>="<bbb>"/>
  <Addin <attributexxx>="<ZZZ>"/>
  <SetProperty Object="<objname>" Name="<name of property>" Type="<TypeName>">Value<\SetProperty>
  <SetEvent Object="<objname>" Name="<EventName>"/>"

When you refresh the page (when the new value is passed into the addin), the XAML from Element tag is used to create the controls. This XAML is not compiled, thus you cannot use things like Event directly in the XAML. But you can use it to define styles and other resources and the controls, which would be inside the addin. Example:




<!—Start of XAML definition -->

<Canvas Name="canvas1"

      <GradientStop Color="Lime" Offset="0.0" />
      <GradientStop Color="Green" Offset="1.0" />
    <Border x:Key="bdrSelected" Width="5" />
    <Style x:Key="styButton">
      <Setter Property="Control.Background" Value="{StaticResource brNumber}" />

  <Grid Width="{Binding ElementName=canvas1, Path=ActualWidth}"
    Height="{Binding ElementName=canvas1, Path=ActualHeight}">
      <ColumnDefinition Width="0.25*" />
      <ColumnDefinition Width="0.25*" />
      <ColumnDefinition Width="0.25*" />
      <ColumnDefinition Width="0.25*" />
      <RowDefinition Height="0.10*" />
      <RowDefinition Height="0.22*" />
      <RowDefinition Height="0.17*" />
      <RowDefinition Height="0.17*" />
      <RowDefinition Height="0.17*" />
      <RowDefinition Height="0.17*" />
    <!-- Row 1 -->
        Background="{StaticResource brNumber}"
        Name="btnNum7" Focusable="False" Tag="7">7</Button>
        Background="{StaticResource brNumber}"
        Name="btnNum8" Focusable="False" Tag="8">8</Button>
      Background="{StaticResource brResult}"

<!—End of XAML definition -->
<Addin AllowCaption="True"/> <Host Background="White""/>
<SetEvent Object="btnCe" Name="Click"/>
<SetEvent Object="btnC" Name="Click"/>
<SetEvent Object="btnNum0" Name="Click"/>
<SetEvent Object="btnNum1" Name="Click"/>
<SetEvent Object="btnNum2" Name="Click"/>

This is example of the XML. First it define the XAML for the controls. Tag properties are used to return some integer in first parameter of the NAV event. Events are connected to the NAV event by using “SetEvent”element. You just pass the control name and name of the event. If it is supported type event, it will be connected to NAV event handler inside the addin. Addin element just set one property of the addin – if the Caption should be displayed or not. Host element set property of the ElementHost object used to host the WPF controls on the page. See the ElementHost properties on MSDN documentation to see what you can set.

If all is ok, the page will open with some buttons in a grid and one label. When you click the button, NAV event will be triggered and the Tag of the button will be passed in Index parameter and simple XML will be passed in the Data parameter. The XML looks like this:


You can use the XML to check which specific event was triggered and on which control, because some controls could have more triggers connected into NAV (e.g. MouseEnter, MouseLeave etc.). You can react to the event in the NAV as you wish. You can e.g. dynamically change some properties of selected controls inside the addin by passing XML like this to the addin:

   <SetProperty Object="lblResult" Name="Content" Type="System.String">

This example will set the content of the label to string “MyData”. Because the PF controls are able to display different content, not just strings, you need to enter correct type and correctly format the inside XML for this tag. I can imagine that you will e.g. pass some picture or some other controls… If the page is refreshed, the addin will display the updated controls.


You can download the files there.