0

I want a property to be display only if another boolean property is set to true.

I don't know how to create this dinamically visulization. The property browsable is waiting a bool value

There is no problem to this property be serialized or not.

[DataMember(Order = 1)]
[Display(Name = "Checked")]
public bool IsChecked{ get; set; } = true;
    
[DataMember(Order = 2)]
[Display(Name = "Address")]
[IsBrowseable(IsChecked)]
public string Address{ get; set; }
3
  • How do you want to display it (HTML, Winforms, WPF, ..) what have you tried so far and what's the problem? Commented Dec 22, 2020 at 13:26
  • Hello @ChristophLütjen, I'm trying to apply it on a WPF application. I only tried to find a attribute that could be good, as this browsable. With the browsable as the way I've added it show an error "An object reference is required for the non- static field" Commented Dec 22, 2020 at 13:32
  • I'm can't help you with WPF, but from a quick search, this looks like it could help: stackoverflow.com/questions/30172392/… - if not: It often helps, if you add your XAML code too to allow readers here to fully understand your problem. It's really important to re-read questions on SO and check if other have a chance to understand it without knowing anything from your project except what you provided in you question. Commented Dec 22, 2020 at 13:42

1 Answer 1

0

That's not possible, in this case the attribute argument value must be a compile-time constant. Changing IsChecked while the application is running would not affect the attribute anyhow, so in your case doing [IsBrowseable(true)] would have the same result as using the IsChecked property with it's default value.

For more information check out MSDN's C# language specification for attributes which states the following:

An expression E is an attribute_argument_expression if all of the following statements are true:

  • The type of E is an attribute parameter type (Attribute parameter types).
  • At compile-time, the value of E can be resolved to one of the following:
    • A constant value.
    • A System.Type object.
    • A one-dimensional array of attribute_argument_expressions.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.