How is it possible to stuff a Grid inside a TextBlock?

前端 未结 1 1470
不思量自难忘°
不思量自难忘° 2021-01-15 14:38

The other day I ran into the following xaml and I freaked out:


    

        
1条回答
  •  孤城傲影
    2021-01-15 15:24

    The simple answer is that you can drive TextBlock in two ways ... through the Text property and through the Inlines collection.

    In this case, you are using the Inlines collection.

    TextBlock (via the IAddChild.AddChild method on TextElement) is smart enough to wrap that Grid into an InlineUIContainer ... which is, of course, an Inline.

    In other words, the above xaml ... is the same as:

    
        
            
                
                    
                
            
        
    
    

    Hope this helps someone to avoid the freakout I had. Heh, heh. Well, at least, I hope it calms them down with an understanding of how it works.

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