Default Constructor Parameter in MarkupExtension declaration

后端 未结 1 1945
梦毁少年i
梦毁少年i 2021-02-05 15:33

Reducing this question to the bare minimum, consider this MarkupExtension class...

public class ProblemStatement : MarkupExtension
{
    private readonly string          


        
1条回答
  •  抹茶落季
    2021-02-05 16:04

    Try this out:

        public string Optional{ get; set; } = "DefaultValue";
    
        private readonly string _mandatory;
    
        public ProblemStatement(string mandatory)
        {
            _mandatory = mandatory;
        }
    

    Usage:

    
    

    Alternative:

    
    

    Result:

    • No XAML parsing errors
    • No need to overload the constructor for optional parameters
    • Mandatory parameters are constructor parameters.
    • Optional parameters are properties.

    0 讨论(0)
提交回复
热议问题