Converting ControlTemplate XAML to C#

前端 未结 2 431
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 18:30

I have been stumped with trying to convert the following code into pure c#. This XAML code is from Cavanaghs blog on how to make rounded corners on anything. The code work

2条回答
  •  误落风尘
    2020-12-19 19:18

    You don't actually have to convert this into C# to apply it dynamically. If you add it to your application resources, within your App.xaml file as follows:

    
        
            
                
                
                    
                        
                    
                    
                    
                
            
        
    
    

    Note the x:Key attribute which keys this item.

    You can then look it up anywhere in your code ...

    ControlTemplate template = this.Findresource("MyListViewItemTemplate") as ControlTemplate
    

    You can then apply it as and when you need it!

提交回复
热议问题