You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have 2 TextFields on 2 different QML (tabs) that bound to 2 different properties on the same .NET instance. When the properties get updated, the TextField on the first tab does not get updated. Here is a sample code: QmlNetTest.zip
TestNetType.cs
public class TestNetType : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private string _name;
public string Name
{
get => _name;
set
{
if(_name != value)
{
_name = value;
OnPropertyChanged();
}
}
}
private string _value;
public string Value
{
get => _value;
set
{
if (_value != value)
{
_value = value;
OnPropertyChanged();
}
}
}
}
Program.cs
class Program
{
public static TestNetType TestNetType { get; } = new TestNetType() { Name = "Test Name", Value = "Test Value" };
static int Main(string[] args)
{
try
{
RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();
QQmlApplicationEngine.ActivateMVVMBehavior();
using (var application = new QGuiApplication(args))
using (var qmlEngine = new QQmlApplicationEngine())
{
Qml.Net.Qml.RegisterType<TestNetType>("DotNetViewModels");
Qml.Net.Qml.RegisterType<ViewController>("DotNetViewModels");
qmlEngine.Load("./Views/MainView.qml");
return application.Exec();
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
return -1;
}
}
}
ViewController.cs
public class ViewController
{
public TestNetType TestNetType => Program.TestNetType;
private static int _count;
public void Update()
{
_count++;
TestNetType.Name = $"Test Name {_count}";
TestNetType.Value = $"Test Value {_count}";
}
}
The text was updated successfully, but these errors were encountered:
walbarm
changed the title
Multiple bindings on the same .NET instance, last binding breaks previous ones
Multiple bindings on the same .NET instance, last binding breaks previous ones (help wanted)
Feb 8, 2021
I have 2 TextFields on 2 different QML (tabs) that bound to 2 different properties on the same .NET instance. When the properties get updated, the TextField on the first tab does not get updated. Here is a sample code:
QmlNetTest.zip
TestNetType.cs
Program.cs
ViewController.cs
MainView.qml
Tab1View.qml
Tab2View.qml
The text was updated successfully, but these errors were encountered: