[GH-ISSUE #8] Support INotifyPropertyChanging. #4

Closed
opened 2026-05-05 10:58:40 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @pauldotknopf on GitHub (Jul 15, 2018).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/8

Waiting for #7 to complete.

Originally created by @pauldotknopf on GitHub (Jul 15, 2018). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/8 Waiting for #7 to complete.
Author
Owner

@pauldotknopf commented on GitHub (Jul 16, 2018):

Decided not to implement this. It will be up to the user to manually activate signals when data changes.

<!-- gh-comment-id:405342895 --> @pauldotknopf commented on GitHub (Jul 16, 2018): Decided not to implement this. It will be up to the user to manually activate signals when data changes.
Author
Owner

@ghost commented on GitHub (May 12, 2022):

Not too bad -- I started off by implementing pieces of INotifyPropertyChanged, and then swapping out pieces for Qml Signals:

//Program.cs
namespace QmlNetApp1
{
    class Program
    {
        static int Main(string[] args)
        {
                    // Register our new type to be used in Qml
                    Qml.Net.Qml.RegisterType<MainWindowCode>("code", 1, 1);
        }
    }
}

//MainWindow.qml

import code 1.1

ApplicationWindow 
{
    id: mainWindow

    MainWindowCode
    {
        id: code
		onPropertyChanged: function(propertyName) 
        {
            switch(propertyName) 
            {
                case "SomeString":
                    txtSomeString.text = code.someString
                    break;
				default:
                    console.log("code.onPropertyChanged" + propertyName)
            } 
        }
    }
}

//MainWindow.qml.cs
namespace QmlNetApp1
{
    [Signal("propertyChanged", NetVariantType.String)]
    public class MainWindowCode //: //using Qml Signals instead
        //INotifyPropertyChanged
    {
	#region INotifyPropertyChanged 
        //If property of object changes, call OnPropertyChanged, which notifies any subscribed observers by firing PropertyChanged.
        //Called by all 'set' statements in IModelComponent object properties.
        //public event PropertyChangedEventHandler PropertyChanged;
        //Implementing INotifyPropertyChanged was mostly an exercise in organizing the class as desired; 
        // this method will raise a Qml Signal
        protected void OnPropertyChanged(String propertyName)
        {
            try
            {
                //if (this.PropertyChanged != null)
                //{
                    Console.WriteLine("OnPropertyChanged:"+propertyName);
                    //this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));//Note: this notification not likely to actually be watched, ...
                    this.ActivateSignal("propertyChanged", propertyName);//Note: ...qml file will be watching for this notification instead.
                //}
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
        #endregion INotifyPropertyChanged 

        private String _SomeString = String.Empty;
        public String SomeString
        {
            get { return _SomeString; }
            set 
            { 
                _SomeString = value;
                OnPropertyChanged("SomeString");
                // Console.WriteLine("SomeString:"+value.ToString());
            }
        }

    }
}

<!-- gh-comment-id:1124428142 --> @ghost commented on GitHub (May 12, 2022): Not too bad -- I started off by implementing pieces of INotifyPropertyChanged, and then swapping out pieces for Qml Signals: ``` //Program.cs namespace QmlNetApp1 { class Program { static int Main(string[] args) { // Register our new type to be used in Qml Qml.Net.Qml.RegisterType<MainWindowCode>("code", 1, 1); } } } ``` ``` //MainWindow.qml import code 1.1 ApplicationWindow { id: mainWindow MainWindowCode { id: code onPropertyChanged: function(propertyName) { switch(propertyName) { case "SomeString": txtSomeString.text = code.someString break; default: console.log("code.onPropertyChanged" + propertyName) } } } } ``` ``` //MainWindow.qml.cs namespace QmlNetApp1 { [Signal("propertyChanged", NetVariantType.String)] public class MainWindowCode //: //using Qml Signals instead //INotifyPropertyChanged { #region INotifyPropertyChanged //If property of object changes, call OnPropertyChanged, which notifies any subscribed observers by firing PropertyChanged. //Called by all 'set' statements in IModelComponent object properties. //public event PropertyChangedEventHandler PropertyChanged; //Implementing INotifyPropertyChanged was mostly an exercise in organizing the class as desired; // this method will raise a Qml Signal protected void OnPropertyChanged(String propertyName) { try { //if (this.PropertyChanged != null) //{ Console.WriteLine("OnPropertyChanged:"+propertyName); //this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));//Note: this notification not likely to actually be watched, ... this.ActivateSignal("propertyChanged", propertyName);//Note: ...qml file will be watching for this notification instead. //} } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } #endregion INotifyPropertyChanged private String _SomeString = String.Empty; public String SomeString { get { return _SomeString; } set { _SomeString = value; OnPropertyChanged("SomeString"); // Console.WriteLine("SomeString:"+value.ToString()); } } } } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#4
No description provided.