asusralis
Topic Author
Posts: 97
Joined: 30 Jul 2018, 05:03

Is it possible to create readonly dependency properties?

26 Oct 2020, 23:05

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?
 
User avatar
sfernandez
Site Admin
Posts: 1975
Joined: 22 Dec 2011, 19:20

Re: Is it possible to create readonly dependency properties?

27 Oct 2020, 12:53

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?
 
asusralis
Topic Author
Posts: 97
Joined: 30 Jul 2018, 05:03

Re: Is it possible to create readonly dependency properties?

28 Oct 2020, 04:34

Ah yes, that works. Thanks.

Who is online

Users browsing this forum: No registered users and 9 guests