Creating an instance of a nested class in XAML

后端 未结 3 959
攒了一身酷
攒了一身酷 2020-11-27 17:37

in a XAML file (a WPF UserControl), is there a way to reference an inner class \"B\" defined in another class \"A\" ?

publi         


        
3条回答
  •  隐瞒了意图╮
    2020-11-27 18:42

    . refers to a property; not sure why XAML couldn't also search for a nested class, but it doesn't.


    A nested class can be represented when inside a string (e.g. a property value), using A+B instead of A.B:


    As an element name (as shown in question), + is not allowed, as the result would no longer be valid XML; + is not a valid name character:
    XAML is XML.
    XML Spec - NameChar.

    So the element name cannot directly describe a nested class.
    BUT see UPDATE below - an alternative syntax that solves this.


    UPDATE
    Per @Artfunkel's comment on one answer, this should be a solution [I have not tested]:

    
    

    From: https://docs.microsoft.com/en-us/dotnet/framework/xaml-services/x-type-markup-extension

    TBD how to specify properties with that syntax. Use x:TypeArguments?

提交回复
热议问题