Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of C # WPF data binding templating operation

Shulou Source: shulou.com Published: 2022-06-02 03:51:47 09月29日 Update

Today Xiaobian to share with you what is the method of C# WPF data binding template operation of the relevant knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

The specific example code is as follows: public class NotifyPropertyObject: INotifyPropertyChanged {public event PropertyChangedEventHandler PropertyChanged; public void RaisePropertyChanged (string propertyName) {if (PropertyChanged! = null) {PropertyChanged.Invoke (this, new PropertyChangedEventArgs (propertyName));}} private MainWindowVM vm = new MainWindowVM () / / key public MainWindow () {InitializeComponent (); this.DataContext = vm;// key}

Step 2: create its model class for each interface, such as MainWindowVM,AzimuthWindowVM.,. Classes of this type also need to inherit from the class NotifyPropertyObject

Note: (1) the background implementation code is mainly added to this class, one is to make the background code as simple as possible, and the other is to facilitate data binding.

(2) in most cases, properties and methods are written in this class.

Example:

Public class MainWindowVM: NotifyPropertyObject {private double _ dmsL0; / / Central meridian longitude public double dmsL0 {get {return _ dmsL0;} set {_ dmsL0 = value; RaisePropertyChanged ("dmsL0") } public class AzimuthWindowVM: NotifyPropertyObject {private string azName = "A001-> B004 coordinate azimuth"; public string AzName {get {return azName;} set {azName = value; RaisePropertyChanged ("AzName");}

Step 3: if there is an interface-related quantity in the class, let the class inherit the class NotifyPropertyObject and bind it in the Set code block in the attribute in the derived class.

Public class Ellipsoid: NotifyPropertyObject {private double _ a; / / long axis public double a {get = > _ a; set {_ a = value; if (_ a > 0 & & f > 0) {Init (a, f) } RaisePropertyChanged ("a");}

Step 4: bind in the interface design code

Example:

1, 2, 3, Title= "{Binding Title}" Note: the title can also be bound. The above is all the content of the article "what is the method of templated operation of C # WPF data binding?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Code knowledge articles data methods interfaces templates caches content background properties examples key points different large central coordinates most meridian meridian Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS Redmi OPPO Reno MariaDB