period in XML tags

前端 未结 5 1427
难免孤独
难免孤独 2021-01-12 13:20

Studying XAML now, I keep seeing XAML tags in the format Object.Attribute. For example:

 
     OutOfBrowserSettings Sh         


        
5条回答
  •  心在旅途
    2021-01-12 13:47

    The short answer is that this is purely a XAML construct and it has no relevance in XML.

    For XML a name with dot like is just a unique tag name by itself with the dot being part of the name just like you can have a gmail id with dot in it. It has no special importance or meaning.

    Why XAML uses the dot? This is simply a XAML format that means we are setting the said property of the element object. This is essentially for the XAML engine to process this and and it also makes the XAML readable and easy to understand.

    Additional Info: Nice to know.

    XAML in essence contain pairs of properties and its values and since they represent rather complex objects (leads to deeper hierarchy), it helps in determining which element is the property and which one is the value.

    Whenever XAML compiler or you see , it means the Y property of X is being set.

    It's also worth noting that XAML doesn't allow you to just stick in any XML code for values, the values are always wrapped up in relevant XAML objects and that's how it knows how to process that value.

    For example:

        
            
                Item One
            
            
                Item Two
            
        
    

    It is easy to conceptually see that in above but of course the common and recommended syntax is following which is just short and easy to see:

        
            
            
        
    

    It may not make too much sense in the simple case but imagine your combobox item is a complex item (Say a C# class named House which was two properties Bedrooms and Baths). Then the ComboBoxItem will look like this:

            
                
            
    

    So now since its ComboBoxItem, you can selected it etc and do any operation that you would could on an item in combobox. Because you have tag, you can contain any complex structure inside that (for example using panels) and XAML engine will know all that is one item. It can probably figure that out without this tag too but imagine how difficult would it be for someone to read and understand that code.

    This is also why when you are providing Style, you wrap your styles in top Style object as below:

        
    

    And this is also why there usually is a deeper hierarchy in XAML, one thing into another, that into another, that into another :)

提交回复
热议问题