Skip to content

IFCTerrain Databinding

Marcus Schroeder edited this page Sep 28, 2021 · 3 revisions

Databinding is a frequently used technology in connection with WPF applications.

General

The following lecture (german) might be helpful for familiarization:

  • Visual C# - Grundlagen - Profiwissen - Rezepte (Autor: Jürgen, Kotz; 2019)
  • WPF 4.5 und XAML - Grafische Benutzeroberflächen für Windows (Autor: Jörg Wegener) (Kapitel 7 und 8)

The following is a brief summary, which can also be found in the above-mentioned lecture.

  • The goal of the data binding with IfcTerrain / DTM2BIM is to configure the Config.cs direct to configure. This has the advantage that already existing enumerations (e.g.: BIMGISINteropLibs/IFC/WriteInput.cs --> SurfaceType) can be used. In addition, it has the advantage that the configuration is "more stable" and does not have to be prepared with "many" functions & queries in the code-behind.

  • What is databinding in the context of IfcTerrain? ([!]add example from MainWindow.xaml[!])

Getting started:

A c# class can be used for data binding it must first be prepared. The following example will use: BIMGISInteropLibs.IfcTerrain/Config.cs.

The following namespaces are required:

  • System.ComponentModel - implement the interface "property changed"
  • [Code behind] System.Collections.ObjectModel - observable collection

The class to be used for data binding must implement the interface: INotifyPropertyChanged. For this to be valid the event:

public event PropertyChangedEventHandler PropertyChanged;

This allows the GUI to see "changes" and thus change "properties" and also visualize the change.
To make this possible it is recommended to use the following function as a template as a "template":

private void NotifyPropertyChanged(string propertyName)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

By means of this function it is checked whether the "property" has really changed.

Using the property - "filePath" as an example:

  • (1) Define a private local storage property:
private string _fileName { get; set; }

This is used to initialize a property and can be used for subsequent public property.

  • (2) Define a public property:
public string fileName
{
    get { return _fileName; }
    set
    {
        _fileName = value;
        NotifyPropertyChanged(nameof(fileName));
    }
}

This initially (when initializing) uses the private property and can be overwritten later (using "set").