Page 1 of 1

Is it possible to create readonly dependency properties?

Posted: 26 Oct 2020, 23:05
by asusralis
It seems DependencyPropertyKey is not in Noesis which is how I typically create readonly properties in WPF. Is there another way to do this in Noesis or is this feature not in yet?

Re: Is it possible to create readonly dependency properties?

Posted: 27 Oct 2020, 12:53
by sfernandez
No, that feature is not implemented in C# yet, I added ticket #1823 to track this feature.

Right now read-only properties can be emulated by making private the property identifier and the setter:
public class MyClass : DependencyObject
{
  private static readonly DependencyProperty SomethingProperty = DependencyProperty.Register(
    "Something", typeof(string), typeof(MyClass), new PropertyMetadata(string.Empty));
    
  public string Something
  {
    get { return (string)GetValue(SomethingProperty); }
    private set { SetValue(SomethingProperty, value); }
  }
}
Could that work for you in the meantime?

Re: Is it possible to create readonly dependency properties?

Posted: 28 Oct 2020, 04:34
by asusralis
Ah yes, that works. Thanks.