Two way binding not working on read-only properties?
Hello guys
Like to get an understanding of why this happens here:
Im working in C# in Unity, I have this control in XAML file
<CheckBox Content="BooleanBinding Test" x:Name="TestCheckbox" IsChecked="{Binding AutoBoolValue, Mode=TwoWay}"/>
The data context of TestCheckbox is set to this class BindingContainer_Bool
Where the IsChecked property is binding to the class's AutoBoolValue property
Where the getter and setter are point to a bool member variable inherited from parent class
Code of this class can be seen below
It is throwing an error in Unity
"[NOESIS/E] A TwoWay or OneWayToSource Binding cannot work on a read-only property"
I checked the NoesisGUI documentation, the CheckBox's IsChecked property is not read only
Anyone has idea on this?
Like to get an understanding of why this happens here:
Im working in C# in Unity, I have this control in XAML file
<CheckBox Content="BooleanBinding Test" x:Name="TestCheckbox" IsChecked="{Binding AutoBoolValue, Mode=TwoWay}"/>
The data context of TestCheckbox is set to this class BindingContainer_Bool
Where the IsChecked property is binding to the class's AutoBoolValue property
Where the getter and setter are point to a bool member variable inherited from parent class
Code of this class can be seen below
Code: Select all
public class BindingContainer_Bool: DataContainer_Bool,INotifyPropertyChanged
{
public bool AutoBoolValue => Value;
protected override void OnValueChanged(bool newValue)
{
base.OnValueChanged(newValue);
OnPropertyChanged(nameof(AutoBoolValue));
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
It is throwing an error in Unity
"[NOESIS/E] A TwoWay or OneWayToSource Binding cannot work on a read-only property"
I checked the NoesisGUI documentation, the CheckBox's IsChecked property is not read only
Anyone has idea on this?
Re: Two way binding not working on read-only properties?
The error is referring to the bound DataContext property AutoBoolValue, which is defined as a read-only expression.
For writable properties you need an expression for get and set.
For writable properties you need an expression for get and set.
Code: Select all
public bool AutoBoolValue
{
get => Value;
set => Value = value;
}
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Two way binding not working on read-only properties?
As Mark indicated the error message is referring to the view model property AutoBoolValue, that is read-only. We need to improve the message to make this more clear, something like:
Could you please report this in our bugtracker?
Code: Select all
A TwoWay or OneWayToSource binding cannot work on the read-only property 'AutoBootValue' of type 'NS.BindingContainer_Bool'
Re: Two way binding not working on read-only properties?
The above suggestion works.
And yes the error message is quite misleading
And yes the error message is quite misleading
Re: Two way binding not working on read-only properties?
Thanks! Ticket #2602 created to improve the error message.
Who is online
Users browsing this forum: Google [Bot], vinick and 56 guests