Inheritance from Dependencyobject
To work, I decided to create a primitive DependencyObject, which is a property of the control. However, Noesis writes that this object should be thread-free.
Error:
ArgumentException: Dependency property 'SmartTwin.UI.Controls.TextBoxWrapper.ValueHandler' default value must be free threaded
Noesis.DependencyProperty.ValidateDefaultValue (System.String name, System.Type type, System.Type owner, System.Object value) (at
Code: Select all
public abstract class ValueHandler : DependencyObject
{
public abstract Type ValueType { get; }
public ValueHandler()
{
}
public abstract bool Handle(string oldText, string newText, out string resultText);
}
ArgumentException: Dependency property 'SmartTwin.UI.Controls.TextBoxWrapper.ValueHandler' default value must be free threaded
Noesis.DependencyProperty.ValidateDefaultValue (System.String name, System.Type type, System.Type owner, System.Object value) (at
Re: Inheritance from Dependencyobject
So I made a mistake and realized that the class needs to be inherited from Freezable so that it can be used in defaultValue when registering in DependencyProperty. Is there any practice showing when it is better to use DependencyObject and when Freezable?
-
sfernandez
Site Admin
- Posts: 3000
- Joined:
Re: Inheritance from Dependencyobject
You can define a DependencyProperty of a type inheriting from DependencyObject, but in that case the default value should be null. Otherwise that DependencyObject instance set as default value could be accessed from different threads.
If you want to set a non-null default value you should create a Freezable inherited object and Freeze() it.
If you want to set a non-null default value you should create a Freezable inherited object and Freeze() it.