WPF - Create reusable style with variables/parameters

后端 未结 2 622
自闭症患者
自闭症患者 2020-12-19 07:29

I have an WPF application which contains several TabItems. Each TabItem is different from each other, with a text and an icon.

This is how the TabItem´s style is def

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 08:31

    One way of doing it would be, if you have fixed number of TabItems and you dont want to generate the TabItems through ItemsSource Binding on TabControl. Then in your TabItem.Style you can use Resource keys to get the Text and Source like:

        
             
             
         
    

    and for your TabItems you can define these resources:

         
             
                   TabItem1
                   image/1.png
                   image/2.png
              
          
           
             
                   TabItem2
                   image/3.png
                   image/4.png
              
          
    

    Also you will need to update your Style to set the HeaderTemplate instead of Header

         
    

提交回复
热议问题