Zenon WPF Element
Zenon WPF Element
Zenon WPF Element
Distribution and/or reproduction of this document or parts thereof in any form are permitted solely
with the written permission of the company COPA-DATA. Technical data is only used for product
description and are not guaranteed properties in the legal sense. Subject to change, technical or
otherwise.
Contents
3 Basics ............................................................................................................................................................. 6
3.1 WPF in process visualization.........................................................................................................................7
3.2 Referenced assemblies ...................................................................................................................................8
3.3 Workflows ......................................................................................................................................................... 10
3.3.1 Workflow with Microsoft Expression Blend ................................................................................................ 11
3.3.2 Workflow with Adobe Illustrator ..................................................................................................................... 11
GENERAL HELP
If you cannot find any information you require in this help chapter or can think of anything that you
would like added, please send an email to [email protected].
PROJECT SUPPORT
You can receive support for any real project you may have from our customer service team, which
you can contact via email at [email protected].
2 WPF element
With the WPF dynamic element, valid WPF/XAML files in zenon can be integrated and displayed.
Note: In the zenon Editor, the standard tooltip for the WPF element is not displayed if a .wpf file is
linked. Furthermore, in zenon Runtime, the zenon tooltip for WPF elements is not supported.
Information
All brand and product names in this documentation are trademarks or
registered trademarks of the respective title holder.
5 | 131
Basics
3 Basics
XAML
XAML stands for Extensible Application Markup Language. The XML-based descriptive text developed
by Microsoft defines graphic elements, animations, transformations, displays of color gradients etc. in
Silverlight and WPF user interfaces. The use of XAML makes it possible to strictly separate design and
programming. The designer prepares, for example, the graphical user interface and creates basic
animations that are then used by the developers/project planners who create the application logic.
WPF
WPF stands for Windows Presentation Foundation and describes a graphics framework that is part of
the Windows .NET framework:
WPF provides a comprehensive model for the programmer.
XAML describes, based on XML, the interface hierarchy as a markup language. Depending
on the construction of the XAML file, there is the possibility to link properties, events and
transformations of WPF elements with variables and functions of
CD_PRODUCTNAME<.
The framework unites the different areas of presentation such as user interface, drawing,
graphics, audio, video, documents and typography.
For execution in zenon, Microsoft .NET framework version 4.6.2 or higher is required.
Information
Transparency
In order for WPF controls in which a transparent background has been defined
to also be displayed as transparent, the following must be the case on the
computer for both Editor and Runtime:
The operating system must be at least Windows 8.1
The .NET framework version 4.6.2 or higher must be installed
6 | 131
Basics
Graphics no longer need to be drawn in zenon, but can be imported directly as an XAML file. This
makes it possible to use complex, elaborately illustrated elements in process visualization. Reflections,
shading, 3D effects etc. are supported as graphics. The elements that are adapted to the respective
industry environment make intuitive operation possible, along the lines of the operating elements of
the machine.
The integration of XAML-based display elements improves the graphics of projects and makes it very
easy to display processes clearly. Elements optimized for usability make operation easier. A clear
display of data makes it easier to receive complex content. The flexible options for adapting individual
elements makes it easier to use for the operator. It is therefore possible for the project planners to
determine display values, scales and units on their own.
Grouped display elements make it possible to clearly display the most important process data, so that
the equipment operator is always informed of the current process workflow. Graphical evaluations,
display values and sliders can be grouped into an element and make quick and uncomplicated
control possible.
7 | 131
Basics
INDUSTRY-SPECIFIC DISPLAYS
Elements such as thermometers, scales or bar graphs are part of the basic elements of process
visualization. It is possible, using XAML, to adapt these to the respective industry. Thus equipment
operators can find the established and usual elements that they already know from the machines in
process visualization at the terminal.
Illustrations can be adapted to the respective style requirements of the company, in order to achieve
a consistent appearance through to the individual process screen. For example, the standard
operation elements from zenon can be used, which can then be adapted to color worlds, house fonts
and illustration styles of the corporate design.
For example, a user control that looks like a tacho and provides special properties and optical effects
can be created, such as a Value property, which causes the pointer of the tacho to move and/or the
corresponding value to be displayed in a label.
Procedure:
Draw the appearance of the user controls with standard objects that are offered by WPF.
Program the properties and interactions.
Compile the complete package.
The result is available as a .NET assembly.
This assembly can be used for WPF projects. To do this, it must be referenced (linked) in the WPF
editor (for example: Microsoft Expression Blend). To do this, select the assembly in the zenon file
selection dialog:
8 | 131
Basics
From this point in time, the WPF user controls of the assembly in the tool box can be selected under
Custom user controls and used in the WPF project.
Read more about this in the Guidelines for developers (on page 24).
When displaying a WPF file in the WPF element (Editor and Runtime), the assemblies from this folder
are loaded. It is thus also ensured that that when the Runtime files are transferred using Remote
Transport, all referenced assemblies are present on the target computer.
A collective file (.cdwpf) can exist alongside an XAML file with the same name. All assemblies (*.dll)
from all collective files and the Other folder are copied to the work folder. Only the highest file version
is used if there are several assemblies with the same name.
9 | 131
Basics
Hint
DLLs that are part of a WPF element can also be replaced during ongoing
operation. In doing so, the referencing is via linking in the XAML file.
To replace a DLL:
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In Explorer, replace the DLL in the \wpfache folder of the Editor files.
You can find this folder in the SQL directory under
...\PROJECT-GUID\FILES\zenon\custom\wpfcache
As an alternative to replacement using Explorer, you can also replace the file in
the zenon Editor directly. To do this, carry out the following steps:
In the Visual Studio project settings, increase the file version of the DLL.
Create the new DLL.
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In the zenon Editor, delete the DLL from the \Files\Other folder and add the
file with the higher version number.
MULTI-PROJECT ADMINISTRATION
With multi-project administration, the same assembly must be used in all projects. If an assembly is
replaced by another version in a project, it must also be replaced in all other projects that are
loaded in the Editor or in Runtime.
3.3 Workflows
The WPF/XAML technology makes new workflows in process visualization possible. The separation of
design and functionality ensures a clear distinction of roles between the project engineer and
designers; design tasks can be easily fulfilled by using pre-existing designs, which no longer need to
be modified by the project engineer.
The following people are involved in the workflow to create WPF elements in zenon:
Designer
illustrates elements
takes care of the graphics for MS Expression Design
MS Expression Blend operator
10 | 131
Basics
Animates elements
Creates variables for the animation of WPF elements in zenon, which project engineer
can access
Project engineer
Integrates elements into zenon:
stores logic and functionality
We make a distinction:
Workflow with Microsoft Expression Blend (on page 11)
Workflow with Adobe Illustrator (on page 11)
You can find an example for creating a WPF elements with Microsoft Expression Blend in the Create
button as XAML file with Microsoft Expression Blend (on page 12) chapter.
You can find an example for creation in the Workflow with Adobe Illustrator (on page 16) chapter.
11 | 131
Guidelines for designers
Information
If referenced objects (assemblies) are used in WPF, note the instructions in the
Referenced objects (on page 8) chapter.
The following example shows the illustration and conversion of a button element into an XAML file.
Note: A test version of "Microsoft Expression Blend" can be downloaded from the Microsoft website.
CREATE BUTTON
1. Start Expression Blend
12 | 131
Guidelines for designers
13 | 131
Guidelines for designers
14 | 131
Guidelines for designers
Margins: 25
12. Save the changes and open the file in Internet Explorer to check it. You will see that the
button is displayed in a size of 50 x 50 pixels.
15 | 131
Guidelines for designers
6. If you now open the file in Internet Explorer, the button is automatically scaled when the IE
window size is changed. This file will now also automatically adapt to changes in the size of
the WPF element in zenon.
CHANGE NAME
Before you can integrate the file into zenon, you must give the WPF element a name. The WPF
elements are not named in Expression Blend as standard, and are labeled with square brackets and
their type. zenon content is assigned to WPF content via the name of the WPF elements:
in tree view, change the name
of the button on MyButton
of the ViewBox to MyViewBox
This button can now be integrated in zenon (on page 117) as an XAML file.
The following example shows the illustration and conversion of a bar graph element into an XAML
file.
16 | 131
Guidelines for designers
NOTES ON COMPATIBILITY
Illustrations that were created with Adobe Illustrator are in principle suitable for WPF export. However,
not all Illustrator effects can become corresponding effects in Expression Design/Blend. Note:
Effect Description
Clipping masks Clipping masks created in Adobe Illustrator are not correctly
interpreted by Expression Design. These are usually shown in
Blend as areas of black color.
Filters and effects Not all Adobe Illustrator filters are transferred into Expression
Design accordingly: Thus blurring filters, shading filters and
corner effects from Illustrator do not work in Expression Design.
Solution:
Most effects can be converted so that they can be read
correctly by Expression Design using the Object ->
Convert appearance command in Adobe Illustrator.
Text fields To be able to link text fields with code, these must be created
separately in Expression Blend. "Labels" are required for dynamic
texts; simple "text fields" are sufficient for static information.
17 | 131
Guidelines for designers
Effect Description
Transparencies and group There can be difficulties in Adobe Illustrator with the correct
transparencies interpretation of transparency settings, in particular from group
transparency settings.
Multiply levels These level settings in Adobe Illustrator are not always correctly
displayed by MS Expression Blend.
Indicating instruments and To prepare the graphics optimally for animation, the indicator
standard positions and slider must always be set to the starting position, usually 0 or
12:00 o'clock.
Thus the position parameters for rotations etc. are also correct in
Blend and an animation can be implemented without conversion
of position data.
Note: There is a free plug-in for the direct export of WPF files from Adobe Illustrator available on the
internet. This plug-in provides a quick, uncomplicated way of exporting from Illustrator, however it is
less suited to the current application because it lead to graphical losses. Even color deviations from
the original document are possible.
Files in .ai format can regularly be imported into Expression Design; the paths are retained in the
process.
Attention: Some common Illustrator effects cannot be displayed by Expression Design correctly
however (see Illustration (on page 16) chapter).
18 | 131
Guidelines for designers
Import the prepared Illustrator file (on page 16) in Microsoft Expression Design via File
-> Import
2. ED: Optimization
If the starting file is not correctly displayed in MS Expression Design, it can still be
subsequently edited and optimized here
3. ED: Select
Highlight the element for WPF export with the direct selection arrow in MS Expression
Design; in this case it is the whole clock
4. ED: Start export
19 | 131
Guidelines for designers
The exported file has .xaml file suffix. It is prepared and animated (on page 20) in MS Expression
Blend in the next stage.
In thirteen steps, we go from a static XAML to an animated element, that can be embedded in zenon:
1. EB:create project
20 | 131
Guidelines for designers
a) Navigate to MainControl.xaml.cs
b) Delete this file using the Delete command in the context menu
3. EB: Open exported XAML file
d:DesignWidth="640" d:DesignHeight="480”
21 | 131
Guidelines for designers
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"
mc:Ignorable="d"
x:Name="UserControl">
<Grid x:Name="LayoutRoot"/>
</UserControl>
22 | 131
Guidelines for designers
a) Click on Layout root -> Change layout type -> Viewbox with the right mouse button
b) The structure should now look like this: UserControl -> LayoutRoot -> Grid -> Elements
c) Assign a name for LayoutRoot and Grid by double-clicking on the names
10. EB: Texts and values
Labels replace numbers that are to be subsequently linked using INT variables (must be
carried out for all number elements)
12. EB: Set property
To display 100%, set the bar graph element's MaxHeight property to 341 (the maximum
height of the indicator element is 340)
13. EB: prepare for use in zenon
a) Delete all name labels (names may only be given for elements that are to be addressed
via zenon)
b) Save the XAML file with any desired name
23 | 131
Guidelines for developers
A hint for checking: If the XAML file is displayed with no problems in Microsoft Internet Explorer
and the window size of Internet Explorer adapts to it, it will also be correctly used in zenon.
Information
Recommendation: Use Microsoft Visual Studio version 2012 or later. The XAML
designer is better integrated in this.
24 | 131
Guidelines for developers
25 | 131
Guidelines for developers
Now you have the user control with the required functionality available. However, because zenon can
only display XAML files that do not link to a code-behind file, an additional XAML file is needed that
references the library (assembly) that has just been built.
5. Because all necessary content is contained in the DLL that has been created and no
code-behind file can be used, delete the following lines:
x:Class="WPFUserControlNoCodeBehind.UserControl1"
xmlns:local="clr-namespace:WPFUserControlNoCodeBehind"
6. Also delete (for the designer's size setting) the following lines:
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
7. Delete the code-behind file (UserControl1.xaml.cs) in this project.
26 | 131
Guidelines for developers
8. Drag the user control that has been created beforehand (for the project
WPFUserControlLibrary) over the toolbox in the XAML designer.
In the next step, how the DLL and XAML file are incorporated into zenon is explained.
STEPS IN ZENON
1. Open the zenon Editor
2. Go to File -> Graphics.
3. Select Add file... in the context menu
4. Select the XAML file at the save location (UserControl1.xaml from the
WPFUserControlNoCodeBehind project) and add this:
5. Insert the DLL with the functionality for the XAML file.
To do this:
27 | 131
Guidelines for developers
Information
The XAML file and referenced assemblies can also be saved in complied form as
a *.cdwpf file. Only one file thus need to be imported in the Editor (under Files
-> Graphics). Further information on this can be found in the CDWPF files
(collective files) (on page 48) chapter.
Hint: When developing a WPF user control, it is usually more practical to insert
the XAML file and the referenced DLL(s) separately. This makes the replacement
of the DLL and debugging easier. Further information on the topic of debugging
can be found in the Debugging the WPF user control in the Runtime (on page
29) chapter.
28 | 131
Guidelines for developers
Hint
DLLs that are part of a WPF element can also be replaced during ongoing
operation. In doing so, the referencing is via linking in the XAML file.
To replace a DLL:
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In Explorer, replace the DLL in the \wpfache folder of the Editor files.
You can find this folder in the SQL directory under
...\PROJECT-GUID\FILES\zenon\custom\wpfcache
As an alternative to replacement using Explorer, you can also replace the file in
the zenon Editor directly. To do this, carry out the following steps:
In the Visual Studio project settings, increase the file version of the DLL.
Create the new DLL.
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In the zenon Editor, delete the DLL from the \Files\Other folder and add the
file with the higher version number.
Further examples can be found in the Examples: Integration of WPF into zenon (on page 112)
chapter.
In this example, the control described in the Creation of a simple WPF user controls with code behind
function (on page 24) is used.
29 | 131
Guidelines for developers
2. Set a breakpoint in the click event of the button in the Visual Studio project
3. In Visual Studio, under Debug , select the Attach to Process menu item.
4. Select the zenon Runtime process
5. Under Attach to, select either Automatic or the corresponding .NET framework version
6. Click on Attach.
30 | 131
Guidelines for developers
7. Now trigger the breakpoint in which you enter values into the WPF control in zenon Runtime
and click on the button
4. In the project properties of the Visual Studio project, select under Debug, for Start action:
Start external program
5. For Start external program, select the path of the zenon Runtime application.
6. Under Working Directory, select the \wpfcache folder of the Runtime files
(...\PROJECTNAME\RT\FILES\zenon\custom\wpfcache)
31 | 131
Guidelines for developers
Hint: In the selected project in the zenon Editor, press the keyboard combination
CTRL+ALT+R in order to jump directly to the root directory of the Runtime files.
7. In the project properties, enter \wpfache folder of the Runtime files as the Output path under
Build .
32 | 131
Guidelines for developers
Information
When starting zenon Runtime, the assemblies (DLLs) referenced in the WPF user
controls from the \FILES\zenon\custom\additional folder, and/or the assemblies
from CDWPF files in the \FILES\zenon\custom\wpfcache folder are copied. If the
file version of the DLL in the \wpfache folder is one higher than the version of
the "original file", it is not replaced!
For debugging, it is thus sufficient to only replace the file that is on the \wpfache
folder directly.
For delivery, it must be ensured that the current version of the DLL is present in
the \additional folder or the CDWPF file!
Attention: If only the DLL is updated in the \additional folder or in the CDWPF,
but the version number is not increased, the DLL must be deleted manually in
the \wpcache folder, because it is not updated otherwise (due to the
above-described mechanism).
Hint
DLLs that are part of a WPF element can also be replaced during ongoing
operation. In doing so, the referencing is via linking in the XAML file.
To replace a DLL:
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In Explorer, replace the DLL in the \wpfache folder of the Editor files.
You can find this folder in the SQL directory under
...\PROJECT-GUID\FILES\zenon\custom\wpfcache
As an alternative to replacement using Explorer, you can also replace the file in
the zenon Editor directly. To do this, carry out the following steps:
In the Visual Studio project settings, increase the file version of the DLL.
Create the new DLL.
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In the zenon Editor, delete the DLL from the \Files\Other folder and add the
file with the higher version number.
33 | 131
Guidelines for developers
The WPF user control project created in the Creating a simple WPF user controls with code behind
function (on page 24) serves as a basis (WPFUserControlLibrary).
In this chapter, the focus is purely on the core theme (Dependency Properties and data exchange
between the user control and zenon in this case). Specific WPF features such as Databinding, etc., as
well as explicit error handling, are not covered.
2. Add the following lines of code in the UserControl1 class of the code behind file
(UserControl1.xaml.cs)
/// <summary>
/// Gets or sets the ValueA.
/// </summary>
public double ValueA
{
get
{
return (double)GetValue(ValueADependencyProperty);
}
set
{
SetValue(ValueADependencyProperty, value);
}
}
34 | 131
Guidelines for developers
/// <summary>
/// Dependency property for ValueA
/// </summary>
public static readonly DependencyProperty ValueADependencyProperty =
DependencyProperty.Register("ValueA", typeof(double),
typeof(UserControl1), new
FrameworkPropertyMetadata(0.0, new
PropertyChangedCallback(OnValueADependencyPropertyChanged)));
/// <summary>
/// Called when [value a dependency property changed].
/// </summary>
/// <param name="source">The source.</param>
OnValueADependencyPropertyChanged(DependencyObject source,
private static void
DependencyPropertyChangedEventArgs e)
{
UserControl1 control = source as UserControl1;
if (control != null)
{
try
{
control.ValueA = (double)e.NewValue;
control.textBoxA.Text = control.ValueA.ToString();
}
catch (Exception)
{}
}
}
/// <summary>
/// Handles the TextChanged event of the textBoxA control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="TextChangedEventArgs"/> instance containing the event data.</param>
35 | 131
Guidelines for developers
ValueA = Convert.ToDouble(textBoxA.Text);
}
catch (Exception)
{}
}
Information
A numerical property (double) is used in this example. Other simple data types
(such as bool, string, int, etc.) can also be used.
LINKING IN ZENON
1. Update the WPF user control (DLL) in the zenon Editor.
2. Proceed as described in the creation of a simple WPF user controls with code behind
function (on page 24) chapter.
3. Create a numeric variable in zenon. Link the variable to a dynamic text element.
You place the dynamic text element in the screen next to the WPF element with your user
control.
4. Open the screen that contains the WPF element.
5. Go to Configuration in the properties of the WPF element in the WPF links property group.
36 | 131
Guidelines for developers
7. Select the line with ValueA(this is the name of the property that was created in the code
beforehand) and select, for Type of link: Variable.
Hint: Give Properties a prefix so that this can be found more easily, for example: _ValueA
8. In the column under Linkage, print out the variable that was created in zenon beforehand
37 | 131
Guidelines for developers
11. If the value is changed in user control, the value automatically changes in zenon and vice
versa.
12. You can of course debug the control as described in the Debugging the WPF user control in
Runtime (on page 29) chapter, and create further dependency properties.
Information
The UserControl_Loaded event can be used in order to (automatically) access the
values of the dependency property during initialization (when calling up the user
control) for example.
The example used here is based on the example used in the Data exchange using dependency
properties (on page 34) chapter.
38 | 131
Guidelines for developers
Whereby:
"Screen" is the name of the zenon screen in which the WPF element is located
"WPF_Element" is the name of the WPF element that contains the WPF user control
is the name of the WPF user controls itself (defined in the
"AdditionControl"
UserControl1.xaml file)
When executing the macro, the value is read by the control, doubled and written back.
Information
The user control properties used for this method of data exchange need not
necessarily be dependency properties, as outlined in this example. "Standard"
properties can also be used, see in relation to this the Access via VSTA "variable
link" (on page 40) chapter.
39 | 131
Guidelines for developers
Attention
When using zenon COM objects with self-created user controls or external
applications, they must be enabled using the Marshal.ReleaseComObject
method. Enabling by means of the Marshal.FinalReleaseComObject method
must not be used, because this leads to a malfunction of zenon Add-ins.
Information
The following code is intended to show an example of how the COM
implements access to zenon Runtime and in doing so limits itself to the basic
functionality. There is no explicit error handling, etc.
40 | 131
Guidelines for developers
After this, the following code must be inserted in the UserControl1 class:
/// <summary>
/// Property for the Variable link via VSTA
/// </summary>
public object zenonVariableLink
{
get { return null; }
set
{
if (value != null && zenonProject == null)
{
zenOn.Variable zenonVariable;
try
{
zenonVariable = (zenOn.Variable)value;
}
catch (Exception)
{
return;
}
if ((zenonVariable!= null) && (!string.IsNullOrEmpty(zenonVariable.Name)))
{
zenonProject = zenonVariable.Parent.Parent;
}
}
}
}
/// <summary>
/// Trigger used to notify the control from VSTA to release the COM resources
/// </summary>
public object zenonReleaseTrigger
{
41 | 131
Guidelines for developers
set
{
if ((bool)value && zenonProject != null)
{
try
{
Marshal.ReleaseComObject(zenonProject);
}
catch (Exception)
{
return;
}
zenonProject = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
}
}
Whereby access to the properties zenonVariableLink (to initialize the COM object) and zenonReleaseTrigger
(to unlock the COM object) are subsequently accessed from VSTA (write).
In order to test the COM access quickly very easily, it is possible to insert the following line of code in
the existing button click event of the user control.
private void buttonAdd_Click(object sender, RoutedEventArgs e)
{
if (zenonProject != null)
{
MessageBox.Show(zenonProject.Name);
}
return;
...
42 | 131
Guidelines for developers
Information
A zenOn.Project variable is used in this example. Of course other objects such as
events, etc. of the zenon object model can also be used.
/// </summary>
public void MacroWPFInit()
{
zenOn.IDynPicture myWPFScreen = this.DynPictures().Item("Screen");
/// </summary>
public void MacroWPFRelease()
{
zenOn.IDynPicture myWPFScreen = this.DynPictures().Item("Screen");
Create two execute VSTA macro functions that are linked with buttons, which are in the same screen
as the WPF element.
43 | 131
Guidelines for developers
Click on the button in the WPF user control; a message box with the project name of the
project appears
In order to debug the user control, it is possible to proceed as described in the Debugging the WPF
user control in Runtime (on page 29).
Hint
The initialization and release of the COM object in this example is only carried
out for simple demonstration using VSTA macro functions. Depending on the
application, and/or in practice, events in VSTA are better suited to this.
For example, the code for initialization in the _Open event of the screen can be
executed with the WPF element and the code for release in the _Close event.
The mechanism described here is also used in the Display of WPF elements in
the zenon Web Client (on page 109) chapter.
Attention
If COM objects are used in WPF user controls, these must always be explicitly
approved before destroying the WPF user control (before closing the screen,
before closing Runtime, before reloading).
44 | 131
Guidelines for developers
Information
The following code is intended to show an example of how the COM
implements access to zenon Runtime and in doing so limits itself to the basic
functionality. There is no explicit error handling, etc.
After this, the following code must be inserted in the UserControl1 class:
//The zenon Project
Furthermore, the constructor of the user controls must be supplemented with the lines below (to
initialize the COM object):
/// <summary>
/// Constructor for UserControl1, initialize COM Object
/// </summary>
public UserControl1()
{
InitializeComponent();
try
45 | 131
Guidelines for developers
zenonProject =
((zenOn.Application)Marshal.GetActiveObject("zenOn.Application")).Projects().Item("TESTPROJECT");
}
catch (Exception)
{
}
}
/// </summary>
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
{
try
{
if (zenonProject != null)
{
Marshal.ReleaseComObject(zenonProject);
zenonProject = null;
}
}
catch (Exception)
{
}
}
In order to test the COM access quickly very easily, it is possible to insert the following line of code in
the existing button click event of the user control.
private void buttonAdd_Click(object sender, RoutedEventArgs e)
{
if (zenonProject != null)
{
MessageBox.Show(zenonProject.Name);
}
return;
...
46 | 131
Guidelines for developers
Now build the solution and update the WPF user control in the zenon project.
In order to debug the user control, it is possible to proceed as described in the Debugging the WPF
user control in Runtime (on page 29).
Information
A zenOn.Project variable is used in this example. Of course other objects such as
events, etc. of the zenon object model can also be used.
Attention
If COM objects are used in WPF user controls, these must always be explicitly
approved before destroying the WPF user control (before closing the screen,
before closing Runtime, before reloading).
Information
No access by means of marshaling is possible in the zenon web client. If access
to the COM interface is required there, the method described in the Access via
VSTA "variable link" (on page 40) must be used.
47 | 131
Engineering in zenon
6 Engineering in zenon
In order to be able to use WPF user controls in zenon, version 4.6.2 (or higher, depending on the
.NET framework version used in the user control) of the Microsoft framework must be used on both
the Editor computer and the Runtime computer.
Attention
If the Runtime files were created for a project for a version before 6.50, existing
WPF elements are not included into Runtime screens.
48 | 131
Engineering in zenon
Information
If referenced assemblies are used, note the instructions in the Referenced
assemblies (on page 8) chapter.
49 | 131
Engineering in zenon
2. The dialog with three tabs opens with a preview of the XAML file and the elements present in
the file
DIALOG CONFIGURATION
Parameter Description
50 | 131
Engineering in zenon
Parameter Description
Information
Only logical objects can be displayed in the configuration dialog. Visual objects
are not displayed. You can read background information and how visual objects
can be animated in the Allocation of zenon object to WPF content.
EDIT HYPERLINKS
All configured hyperlinks can be edited from the properties of the element. Click on the element and
open the property group WPF links. Hyperlinks can be further configured here, without having to
open the dialog.
Limitations:
The linking type cannot be changed here.
New linkings can only be created via the configuration dialog.
Insertion of a WPF elements into a symbol: WPF linkings cannot be exported.
51 | 131
Engineering in zenon
6.3.1 Properties
The properties enable the linking of:
Variables (on page 53)
Values (on page 55)
Authorizations and interlockings (on page 56)
Parameter Description
52 | 131
Engineering in zenon
Parameter Description
Context menu->Column selection.
CREATE LINK
To create a link:
1. Highlight the line with the property that is to be linked
2. Click in the Link type cell
3. Select the desired link from the drop-down list.
The following are available:
<not linked> (deletes an existing link)
Authorization/Interlocking
Constant value
variable
4. Click in the Link cell
5. The dialog for configuring the desired link opens
Information
Properties of WPF and zenon can be different. If, for example the visibility
property is linked, there are three values available in .NET:
0 - visible
1 - invisible
2- collapsed
53 | 131
Engineering in zenon
This dialog also applies for the selection of variables with transformations (on page 59). The
configuration also makes it possible to convert from zenon into WPF units.
Parameters Description
Range of values of the WPF element Data to convert variable values into WPF values.
54 | 131
Engineering in zenon
Parameter Description
String value/numerical Depending on what is selected for the Use string property, a
value numerical value or a string value is entered into this field. A unit
of measurement can also be selected for numerical values.
Unit: Selection of a unit of measurement from the drop down list. You
must have configured this in unit switching beforehand.
55 | 131
Engineering in zenon
CLOSE DIALOG
Options Description
OK Applies settings and closes the dialog.
Parameter Description
56 | 131
Engineering in zenon
Authorization Description
Operating authorization If the user has sufficient rights to operate the WPF element, a
available value of 1 is written to the property.
Operating authorization does If the user does not have sufficient rights to operate the WPF
not exist element, a value of 1 is written to the property.
Not interlocked If the element is not locked, the value 1 is written to the property.
Can be operated If authorization is present and the element is not locked, then a
value of 1 is written to the property.
Cannot be operated If authorization is not present or the element is not locked, then
a value of 1 is written to the property.
57 | 131
Engineering in zenon
6.3.2 Events
Events make it possible to link zenon functions to a WPF element.
Parameter Description
LINK FUNCTIONS
To create a link:
58 | 131
Engineering in zenon
Parameter Description
6.3.3 Transformation
The WPF element does not support rotation. If, for example, the WPF element is in a symbol and
the symbol is rotated, the WPF element does not rotate with it. Therefore there is a different
mechanism for Transformation with WPF to turn elements or to otherwise transform them. These
transformations are configured in the Transformation tab.
59 | 131
Engineering in zenon
Attention: If the content is outside of the WPF element area, this part of the contents is lost or it is
not shown.
Parameter Description
For example, if the linked variable is set at the value of 10, then this
value is written as a WPF target and the WPF element is rotated by 10°.
WPF info Shows the current value for properties in WPF content. For the user, it is
directly visible what type of property it is (Boolean, string, etc.).
60 | 131
Engineering in zenon
LINK TRANSFORMATIONS
To link a transformation with a WPF property:
1. Highlight the line with the property that is to be linked
2. Click in the Link type cell
3. Select from the Transformation drop down list
4. Click in the Link cell
5. The dialog for configuring the variables opens
The configuration also makes it possible to convert from zenon into WPF units.
Parameters Description
Range of values of the WPF element Data to convert variable values into WPF values.
61 | 131
Engineering in zenon
Parameters Description
150, for example, by 180 degrees.
Only XAML files with the correct WPF namespace can be displayed by the WPF element. Files that
use a Silverlight namespace cannot be loaded or displayed. However, in most cases it is suffice to
change the Silverlight namespace to the WPF namespace.
WPF-Namespaces:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
In order to use WPF user controls with code behind, the process as described in the Creating a simple
WPF user control with code behind funciton (on page 24) must be carried out.
62 | 131
Engineering in zenon
SCALABILITY
If the content of a WPF element is adjusted to the size of the WPF element, then the controls of the
WPF element are interlaced in a control that offers this functionality, such as a view box for example.
In addition, it must be ensured that the height and width for this elements are configured as
automatic.
The scaling can also be tested in this manner: If the file has been created correctly, the content will
adjust to the size of the Internet Explorer window.
ERROR MESSAGE
If an invalid file is used in zenon, then an error message is displayed in the output window when
loading the file in the WPF element.
For example:
zenon is already shipped with several WPF elements. More are available for download in the web
shop.
All WPF elements have properties which determine the graphical design of the respective element
(Dependency Properties). Setting the values via an XAML file or linking the property via zenon can
directly change the look in the Runtime. The tables in the description of the individual elements
contain the respective Dependency Properties, depending on the control.
63 | 131
Engineering in zenon
Available elements:
Analog clock (on page 64)
Vertical bar graph (on page 65)
BACnet WPF Control
Comtrade Viewer (on page 66)
Energy class diagram (on page 79)
Progress bar (on page 66)
Pareto diagram (on page 80)
Sankey Diagram (on page 87)
Round display (on page 83)
Temperature control (on page 88)
Universal slider (on page 89)
Waterfall chart (on page 91)
64 | 131
Engineering in zenon
Offset Value in hours (h) which displays the time lag to Int16
the system clock.
65 | 131
Engineering in zenon
ProgressBarMarginDistan Distance of the progress bar box from the element edge Double
ce (left, top, right, down).
ProgressBarPadding Distance of the progress bar from the progress bar box Double
(left, top, right, down).
6.5.4 COMTRADE-Viewer
The COMTRADE-Viewer WPF element is available to partners of COPA-DATA and is available to them
via the COPA-DATA Partner Community (https://www.copadata.com/en-us/partner-community/).
License information
The COMTRADE-Viewer can only be configured in the zenon Editor with a valid
Energy Edition license. If there is no valid license, the WPF is displayed as grayed
out in the Editor. A valid Energy Edition license is also required for display in the
Runtime.
66 | 131
Engineering in zenon
The control supports the graphical analysis of digital error and event data logging of a COMTRADE
file.
Information
The control supports IEEE C37.111 (IEEE Standard Common Format for Transient
Data Exchange (COMTRADE) for Power Systems) standards-compliant files.
ASCII or binary files in accordance with the 1999 or 2013 edition can be
visualized.
Older files or files without a year identification are not supported. A warning
dialog is called up when an invalid/unsupported file is selected.
67 | 131
Engineering in zenon
Zoom in and zoom out using the mouse wheel, scroll bar and Multi-Touch gestures
Enlargement of the area
Selection of the area by clicking the mouse
Move the display area using the right mouse button, scroll bar or Multi-Touch gestures.
Exports selected objects as an CSV file.
Hint
To be able to transport COMTRADE files to the zenon Runtime computer, you
can also use the file transfer of the IEC 61850 driver or the FTP function block of
zenon Logic.
You can find further information about this in the driver documentation of the
IEC 61850 driver or in the zenon Logic documentation.
Information
The switch between the views is integrated in the WPF element. Additional
project configuration of a screen switching function is not necessary.
6.5.4.2 Installation
Requirements:
You must be a registered COPA-DATA Partner.
You need to have access to the COPA-DATA Partner Community already granted.
68 | 131
Engineering in zenon
6.5.4.3 Installation
To create a WPF element
1. Open the zenon Editor
2. In the project manager, go to Files and Graphics.
3. Go to Import file....
4. Select the file Comtrade.cdwpf for importing.
5. Confirm the selection by clicking on Open.
6. Open the screen in which the WPF element is to be inserted.
7. In the vertical menu bar, select the WPF element (WPF).
8. Drag the WPF element in the screen with the left mouse button.
The File selection window is opened.
69 | 131
Engineering in zenon
9. Select the file Comtrade.cdwpf and confirm the input by clicking on OK.
The WPF element is added.
The element with the name COMTRADE.CDWPF can be configured and placed in each zenon screen
type.
The project configuration of Width [pixels] and Height [pixels] of the element depend on the
proportions. This prevents the COMTRADE-Viewer being displayed as distorted in Runtime.
Note: When configuring the project, ensure that there is sufficient size to guarantee a clear overview.
GRAPHICAL AMENDMENTS
You configure the graphic design in the properties of the WPF element.
You can find further information in the configuration of the linking (on page 49) chapter in this
manual.
Hint
The properties for the COMTRADE-Viewer WPF element have a "z" as a starting
color. Use name filtering for a clear display when configuring the linking.
CONFIGURATION PAGE
70 | 131
Engineering in zenon
BUTTONS
CHART
LABEL
71 | 131
Engineering in zenon
CHART
72 | 131
Engineering in zenon
Parameter Description
Windows files is opened.
Default: empty
Default: en
Default: True
73 | 131
Engineering in zenon
Note: This also applies if, in zenon Runtime, there is a switch from one screen to another screen with
the screen switching function.
The COMTRADE Viewer Configuration switching, arranged vertically on the side, switches the display
of the configuration to graphic view and vice versa.
SELECT FILE
The Open... button opens the file selection dialog to select a file.
74 | 131
Engineering in zenon
The information from the *.cfg file allows the evaluation of the *.dat file. It contains the data from
various analog and digital series of measurements of currents and voltages. The data is broken down
into individual data sets and shown in hex format.
*.cfg files
The last entry of a file of this data type is a time multiplier. This entry is multiplied by the time
stamp of one of each entry from the *.dat file when a disturbance is read in. If there is no
time multiplier, a factor with the value of 1 is assumed internally. The *.cfg file is not changed
in the process.
Certain standards apply for the entries of the digital measured values. Example of a
standard-compliant entry of a digital measured value: 1,LOPHC,,,0. However, if there is no
zero at the end of the entry, the COMTRADE-Viewer adds this internally. The *.cfg file is not
changed in the process.
*.dat files
The COMTRADE-Viewer is in a position to read in files of this data type that start with the
index 0 or >1. In doing so, a check is constantly carried out to see whether these data sets
are numbered continually in discrete steps from 1. If there are data sets that are not correctly
numbered, the file cannot be read in.
ANALOG CHANNELS
Parameter Description
DIGITAL CHANNELS
Parameter Description
75 | 131
Engineering in zenon
Parameter Description
the selection of the entry.
SHOW SELECTION
To show your selection in the graphic view, click on the Apply button.
Note: Clicking on the vertically-arranged COMTRADE Viewer Configuration switching only changes
the view. An amended selection of the channels is not taken into account in the process.
Files that are compliant with the IEEE C37.111-2013 (or IEC 60255-24:2013) standard can be read in.
X-values are necessary for the display, which represent the time stamps of the respective recorded
data points.
If this is not the case, there is a calculation of the time stamp using the following entries of the *.cfg
file:
Start time of recording the disturbance (date and time of the first data point)
Number of recorded data points (Samplerate)
Number of data points for each query (Rate)
The selected analog and digital channels can be exported to a CSV file with the CSV-Export button.
GRAPH VIEW
76 | 131
Engineering in zenon
Digital channels
Lower area
AXIS LABELING
Horizontal axis
The horizontal axis represents the complete time period as illustrated in the COMTRADE file
(*.dat).
The scaling of this time axis depends on the enlargement level. The higher the enlargement
selected, the more detailed the time display.
Vertical axis
The vertical axis represents the values.
The scaling of the value axis depends on the enlargement level. The greater the
enlargement selected, the more detailed the display of values.
The labeling of the analog channels is shown vertically next to the values and
corresponds to the measuring unit as defined in the COMTRADE file (*.cfg).
The digital channels are displayed in the sequence as defined in the COMTRADE file
(*.cfg).
The Channel identifier of the COMTRADE file serves as an identifier.
KEY
The color key of the graphs is shown at the head of the graph.
77 | 131
Engineering in zenon
The labeling of the digital channels corresponds to the channel description as defined in the
COMTRADE file (*.cfg).
The colors for each channel are assigned automatically with the configured color palette.
The time is displayed in a footer under the graph. The start time is displayed as a text.
Navigation (scroll and zoom) is always applied to all three areas of the graphic display.
You can move the display within the horizontal time line with the scroll bar.
Zoom in and zoom out
You can zoom at the current position of the mouse pointer in the graph view or reduce
the enlargement.
The selected area is displayed by selecting a display area with the mouse button held
down.
Note: The display of the values is always amended to the selected area. As a result, this
can lead to a flattening of the curve in the enlarged graph view.
Double clicking on the scroll bar resets the enlargement.
ANALYSIS
The precise values at the position of the mouse pointer are visualized with a display in value blocks. A
crosshair offers additional visual support with the exact determination of the reading position.
78 | 131
Engineering in zenon
A reaction matrix must be used to model an energy class diagram. This reaction matrix must be linked
to the variable whose value is envisaged for display and distribution in energy classes. The name of
the variable must be transferred to the "zVariableName" property.
79 | 131
Engineering in zenon
zenonFontID ID for a font from the first font list (font size is Integer
not taken into account)
Note: Additional VSTA programming is necessary for the display of the energy class diagram in the
zenon web client. You can find details on this in the display of WPF elements in the zenon web client
(on page 109).
80 | 131
Engineering in zenon
The following settings can be made in the WPF configuration window under COPADATA-ELEMENT:
Property Function Value
81 | 131
Engineering in zenon
82 | 131
Engineering in zenon
ScaleSweepAngle Angel area which defines the size of the scale. Double
83 | 131
Engineering in zenon
84 | 131
Engineering in zenon
RangexEndValue End value of an area. x stands for the range. The end Double
value is at the same time the start value of the next
respective range:
Range1EndValue: End value of the 1st area
and start value of the 2nd range.
Range2EndValue: End value of the 2nd area
and start value of the 3rd range.
Range3EndValue: End value of the 3rd area
and start value of the 4th range.
Range4EndValue: End value of the 4th area
and start value of the 5th range.
Range5EndValue: End value of the 5th area
and start value of the 6th range.
Range6EndValue: End value of the 6th range.
RangexColorBrush Color of the respective area. x stands for the range. Brush
Available are:
Range1ColorBrush: Color of the first range.
85 | 131
Engineering in zenon
86 | 131
Engineering in zenon
The Sankey wizard must be used to model a Sankey diagram. The wizard creates an XML file that is
then evaluated by the WPF element. To do this, the zSankeyName property must be given the name
of the XML file. The XML file must be in the Other folder of a project. This is saved there by the
wizard.
The following settings can be made in the WPF configuration window under COPADATA-ELEMENT:
Property Function Value
87 | 131
Engineering in zenon
Note: Additional VSTA programming is necessary for the display of the Sankey diagrams in the
zenon Web Client. You can find details on this in the display of WPF elements in the zenon Web
Client (on page 109).
88 | 131
Engineering in zenon
Radius Double
89 | 131
Engineering in zenon
ScaleSweepAngle Angel area which defines the size of the scale. Double
90 | 131
Engineering in zenon
The Meaning and waterfall chart Wizard must be used to model a waterfall diagram. A waterfall can
be modeled with this wizard. The information is saved directly to the variables in the Parameters for
waterfall diagram property (Analyzer variable properties group).
91 | 131
Engineering in zenon
Note: Additional VSTA programming is necessary for the display of the waterfall diagram in the
zenon Web Client. You can find details on this in the display of WPF elements in the zenon Web
Client (on page 109).
The bars of a waterfall diagram can be linked to a function in the Runtime. For display in the Runtime,
the bars, labeling and display of the values for execution with the click of a mouse can be configured
for the waterfall diagram.
Carry out the following configuration to link the columns of your waterfall diagram to a function:
1. Configure the WPF element for the waterfall diagram.
Note: To do this, use the Meaning and Waterfall Chart wizard if possible.
92 | 131
Engineering in zenon
Example
For a bar with the waterfall definition WF= WF1,02,05,#E9ED92; The function
name, for example Function_WF1,02,05, is to be used.
The control offers the possibility to configure BACnet schedule objects in a graphical user interface
and to display these objects.
6.5.12.1 Installation
Requirements:
You must be a registered COPA-DATA Partner.
93 | 131
Engineering in zenon
94 | 131
Engineering in zenon
a) Select the Import file entry in the tool bar of the detail view.
The file selection dialog is opened.
b) Select the file called BacnetSchedulerControl.xaml.
c) Confirm the selection by clicking on the Open button
5. Go to the Miscellaneous subnode.
a) Select the Import file entry in the tool bar of the detail view.
The file selection dialog is opened.
b) Select the file called BacnetSchedulerWPF.dll.
c) Confirm the selection by clicking on the Open button
95 | 131
Engineering in zenon
c) Set the parameters for the element width using the Width [pixels] property and the
height with the Height [pixels] property.
Recommended minimum size: 920 x 920 pixels
Carry out the following steps to set the parameters for your BACnet WPF control:
1. Highlight the desired WPF element.
2. Switch to the WPF links property group.
3. Click the ... button in the Configuration property
4. The dialog to enter elements is opened.
5. Expand the BacnetControlGrid node in the Existing Elements area.
The BacnetSchedulerControl is visible in the node.
6. Click on the BacnetSchedulerControl entry.
The view in the Action Linkings area is updated.
96 | 131
Engineering in zenon
Information
The setting of the parameters of the WPF element are visualized in zenon in the
WPF links properties group of the WPF element. In doing so, each WPF linking
is displayed with a separate subnode or overview of properties.
97 | 131
Engineering in zenon
In zenon Runtime, existing BACnet schedule objects can be read by the PLC, modified in the Runtime
and saved back to the PLC.
98 | 131
Engineering in zenon
In this area, the value of the variable that has been linked in configuration of the control (on page 96)
in the Editor for the ZenonEffectivePeriod option is displayed.
Parameter Description
Use Timespan The parameters for the Effective Period are set in
Runtime. Input is in the input fields From and To.
Inactive:
The Effective Period is not used.
Active:
The Effective Period is entered in Runtime.
Default: inactive
Default: 1. 1. 2018
99 | 131
Engineering in zenon
In this area, the value of the variable that has been linked in configuration of the control (on page 96)
in the Editor for the ZenonWeeklySchedule option is displayed.
Parameters Description
[List of the content of the loaded The schedule is displayed in the Weekly Schedule
Weekly Schedules] list as a list entry. The parameters are set for the
respective list entry:
Day
Selection of the day from a drop-down list.
Time
Entry of the time
Input format: hh:mm:ss:ms
Value
Value of the respective schedule. The value
represents that of the data type:
[0] = NULL
[1] = BOOLEAN
[2] = Unsigned
[3] = REAL
[5] = Double
[6] = OctetString
[7] = CharacterString
100 | 131
Engineering in zenon
Parameters Description
[8] = BitString
[9] = Enumerated
[10] = Date
[11] = Time
[12] = BACnetObjectIdentifier
Default: [0]
Examples:
[1] TRUE
For Boolean with value TRUE
[10] 2/3/2021
For data type date with value February 3, 2021
Date entry in BACnet standard format.
101 | 131
Engineering in zenon
In this area, the value of the variable that has been linked in configuration of the control (on page 96)
in the Editor for the ZenonExceptionSchedule option is displayed.
Parameters Description
102 | 131
Engineering in zenon
Parameters Description
several days.
These days are configured in the
drop-down lists for WeekNDay .
CalenderRef
The Exception Schedule is defined with a
reference to an existing BACNet calender
object.
103 | 131
Engineering in zenon
Parameters Description
Default: empty
104 | 131
Engineering in zenon
Parameters Description
Note:
To achieve this, the Object Instance number
entered in the control must be filled with a 0 in
front.
Example:
CalendarObject Instance Nummer = 1
Input in control = 0000001
[List of the content of the loaded The schedule is displayed in the Expeption
Exception Schedules] Schedule list as a list entry. The parameters
are set with the listed options:
105 | 131
Engineering in zenon
Parameters Description
Event Type:
Corresponds to the selection of the event
types from the option box.
Period:
Display of the date. The display can vary
depending on the selected event type:
[Date] - [Date]
Priority:
Configured priority
TIME VALUES
Parameters Description
106 | 131
Engineering in zenon
Parameters Description
[0] = NULL
[1] = BOOLEAN
[2] = Unsigned
[3] = REAL
[5] = Double
[6] = OctetString
[7] = CharacterString
[8] = BitString
[9] = Enumerated
[10] = Date
[11] = Time
[12] = BACnetObjectIdentifier
Default: [0]
Examples:
[1] TRUE
For Boolean with value TRUE
[10] 2/3/2021
For data type date with value February 3, 2021
Date entry in BACnet standard format.
107 | 131
Engineering in zenon
108 | 131
Engineering in zenon
Note: When opening the VSTA editor, note whether the content of the following code is already
present in the project configuration. For the display of the WPF element in the web client, compare
109 | 131
Engineering in zenon
the existing code and undertake the necessary additions. Please note the comments in relation to this
in the sample code.
VSTA CODE
//As member:
string[] WPFElements ={"WPF_Control", "WPFWebclient_1", "WPFWebclient_2" }; //Names of the WPF screen elements that
appear in the zenon project and that need access to the API (as many/few as you want)
//Add the following three lines of code in the project archive function:
void ThisProject_Active()
{
zScreens = this.DynPictures();
void ThisProject_Inactive()
{
zScreens.Open -= new zenOn.DDynPicturesEvents_OpenEventHandler(zScreens_Open);
zScreens.Close -= new zenOn.DDynPicturesEvents_CloseEventHandler(zScreens_Close);
FreeObjects();
}
{
obDynPicture.Elements().Item(element).set_WPFProperty("ELEMENT", "zenonVariableLink",
this.Variables().Item(0));
}
}
}
void zScreens_Close(zenOn.IDynPicture obDynPicture)
110 | 131
Engineering in zenon
{
foreach (string element in WPFElements)
{
if (obDynPicture.Elements().Item(element) != null)
{
zenOn.IElement zWPFElement= obDynPicture.Elements().Item(element);
zWPFElement.set_WPFProperty("ELEMENT", "zenonTrigger", true);
zWPFElement = null;
}
}
VSTA CODE
zenOn.IDynPicture zScreen = zero;
void ThisProject_Active()
{
zScreen = this.DynPictures().Item(wpfPicture);
void ThisProject_Inactive()
{
zScreen.Open -= new zenOn.OpenEventHandler(zScreen_Open);
zScreen.Close -= new zenOn.CloseEventHandler(zScreen_Close);
111 | 131
Engineering in zenon
FreeObjects();
}
void zScreen_Open()
{
if (zScreen.Elements().Item(wpfElement) != null)
{
zScreen.Elements().Item(wpfElement).set_WPFProperty("ELEMENT", "zenonVariableLink",
this.Variables().Item(0));
}
}
void zScreen_Close()
{
if (zScreen.Elements().Item(wpfElement) != null)
{
zenOn.IElement zWPFElement = zScreen.Elements().Item(wpfElement);
zWPFElement.set_WPFProperty("ELEMENT", "zenonTrigger", true);
zWPFElement = null;
}
}
112 | 131
Engineering in zenon
113 | 131
Engineering in zenon
To do this:
Create a new mathematics variable that calculates the new value in relation to the
scaling, for example:
Variable: 0-1000
Mathematic variable {value created in xaml file}*Variable/1000
114 | 131
Engineering in zenon
115 | 131
Engineering in zenon
3. Select the minimum value, the average value and the maximum value and link each of these
to the corresponding variable in the Content property
4. Select the Slider and link the Value property to the mathematics variables (in our example:
calculation)
116 | 131
Engineering in zenon
As a first step, create a button as described in the Create button as XAML file with Microsoft
Expression Blend (on page 12) chapter. To be able to use the XAML file in zenon, insert this in the
project tree in the Files/Graphics folder.
INTEGRATE BUTTON
Note: A zenon project with the following content is used for the following description:
An empty screen as a start screen
an internal variable int of type Int
117 | 131
Engineering in zenon
118 | 131
Engineering in zenon
EVENTS
2. look for the 'Click' entry, this event is triggered by the WPF element, as soon as the button is
clicked
3. Click in the Link type column
4. Select Function from the drop down list
5. Click in the Link column
6. the function selection dialog is opened
7. select Function_0
8. Confirm the changes with OK
9. Insert a numerical value element into the screen
10. Link this numerical value element to the int variables too.
11. Compile the Runtime files and start Runtime.
119 | 131
Engineering in zenon
The WPF element is displayed in Runtime, the button text is 0. As soon as you click on the button,
the click event is triggered and the set value function is carried out. The value 45 is sent directly to
the hardware and both numerical value and button display the value 45 .
Define a set value of 30 via the numerical value element; this value is then also assumed by the
WPF element.
OPERATING AUTHORIZATION
Similar to a numerical value, a WPF element can be locked according to authorizations (lock
symbol) or switched to be operable. Set the user authorization level to 1 for the WPF element and
create a user called Test with authorization level 1. In addition, set up the functions Login with
dialog and Logout. You link these two functions with 2 new text buttons on the screen.
In the WPF element configuration dialog, select the MyButton WPF button and select the Properties:
tab
120 | 131
Engineering in zenon
Compile the Runtime file and note that Authorizations to be Transferred must also be selected. After
Runtime has been started, the WPF button is displayed as deactivated on the screen and cannot be
operated. If you now log in as the user Test, the button is activated and can be operated. The button
is locked again as soon as you log out.
TRANSFORMATION
121 | 131
Engineering in zenon
As a result of this, a block is inserted into the XAML file, which save the transformation
settings in runtime.
4. Save the file and replace the old version in zenon with this new file.
5. Open the WPF element configuration dialog again:
a) select the MyButton button
b) select the Transformations tab
122 | 131
Engineering in zenon
Compile the Runtime files and start Runtime. Log in as the Test user and click on the button. The
button has the value 45 and the WPF element rotates by 45°.
123 | 131
Engineering in zenon
124 | 131
Engineering in zenon
After adding the connection, the Server Explorer window should look a little like this:
CREATING A DATASET
1. Right-click on the project
2. Select Add – New Item… in the context menu
3. Create a new DataSet with the name DataSet1.
4. Double click on the DataSet in order to open it in the Designer.
5. Drag the tables that you need (Customersand Orders in this example) to the DataSet design
window.
125 | 131
Engineering in zenon
2. Define the resources and the DataGrid that is to be used in the WPF:
<UserControl.Resources>
<local:DataSet1 x:Key="DataSet1"/>
<CollectionViewSource x:Key="CustomersViewSource" Source="{Binding Path=Customers,
Source={StaticResource DataSet1}}"/>
</UserControl.Resources>
<Grid DataContext="{StaticResource CustomersViewSource}">
<DataGrid Name="DataGrid1" DisplayMemberPath="CompanyName" ItemsSource="{Binding}"
SelectedValuePath="CustomerID" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Grid>
3. Open the code-behind file (UserControl1.xaml.cs) and insert the following lines in the
constructor:
public UserControl1()
{
InitializeComponent();
DataSet1 ds = ((DataSet1)(FindResource("DataSet1")));
DataSet1TableAdapters.CustomersTableAdapter ta = new
DataSet1TableAdapters.CustomersTableAdapter();
ta.Fill(ds.Customers);
CollectionViewSource CustomersViewSource =
((CollectionViewSource)(this.FindResource("CustomersViewSource")));
CustomersViewSource.View.MoveCurrentToFirst();
}
In doing so, the following happens:
The DataSet is obtained
A new TableAdapter is created
The DataSet is filled
126 | 131
Engineering in zenon
BUILD
Now build the solution. The corresponding DLL (DataGridControlLibrary.dll) is created in the output
folder of the project.
However zenon can only display XAML files that cannot be linked to the code behind file, which is
why an additional XAML file is needed that references the DLL that has just been created.
To do this:
1. Create a further project, again as a WPF User Control Library
2. It was called DataGridControl in our example.
3. Insert a reference to the project that has just been built into this new project.
5. Because all necessary content is contained in the DLL that has been created and no
code-behind is necessary, delete the following lines:
x:Class="DataGridControl.UserControl1"
xmlns:local="clr-namespace:DataGridControl"
6. Also delete (for the positioning) the following lines:
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
127 | 131
Engineering in zenon
In the next step, how the DLL and XAML file are added to zenon is explained.
STEPS IN ZENON
1. Open the zenon Editor
2. Go to File -> Graphics.
3. Select Add file... in the context menu
128 | 131
Engineering in zenon
4. Select the XAML file at the save location (UserControl1.xaml from the DataGridControl
project) and add this:
5. Insert the DLL with the functionality for the XAML file.
To do this:
a) Select, in the context menu, File -> OtherAdd file....
b) Select the file DataGridControlLibrary.dll of the first project (DataGridControlLibrary).
129 | 131
Engineering in zenon
Hint
DLLs that are part of a WPF element can also be replaced during ongoing
operation. In doing so, the referencing is via linking in the XAML file.
To replace a DLL:
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In Explorer, replace the DLL in the \wpfache folder of the Editor files.
You can find this folder in the SQL directory under
...\PROJECT-GUID\FILES\zenon\custom\wpfcache
As an alternative to replacement using Explorer, you can also replace the file in
the zenon Editor directly. To do this, carry out the following steps:
In the Visual Studio project settings, increase the file version of the DLL.
Create the new DLL.
Close all zenon screens in which the WPF element is used.
Close all symbols that use a desired WPF element.
In the zenon Editor, delete the DLL from the \Files\Other folder and add the
file with the higher version number.
Xaml file found in %s Warning The name of the collective file and the name of the XAML
with different name, file contained therein do not correspond. To avoid internal
using default! conflicts, the file with the name of the collective file and the
suffix .xaml is used.
no preview image Warning The collective file does not contain a valid preview graphic
found in %s (preview.png or [names of the XAML file].png). Thus no
preview can be displayed.
Xaml file in %s not Error The collective file does not contain an XAML file or several
found or not unique! files with the suffix .xaml. It cannot be used.
Could not remove old Warning There is an assembly that is to be replaced with a newer
130 | 131
Engineering in zenon
Could not copy new Error A new version is available for an assembly in the work folder,
assembly %s but it cannot be copied there. Possible reason: The old
example is still loaded, for example. The old version
continues to be used, the new version cannot be used,
file exception in %s Error A file error occurred when accessing a collective file.
Generic exception in %s Error A general error occurred when accessing a collective file.
131 | 131