Customizing the toggle state of a toggle button in wpf

前端 未结 4 689
我在风中等你
我在风中等你 2020-12-30 11:48

I wanna customize the toggle state of the toggle button in wpf. I want to set a image to the toggle button when it is on and set another image when it is off. TO do so, i th

4条回答
  •  青春惊慌失措
    2020-12-30 12:33

    The issue here is because you are using Image resources. The Image in your resources is a concrete instance of a control. It can only be in one place at a time. So when you have more than one item in your list...

    This should work for you:

    
    

    Note that you can improve the performance of this by using an ImageSource for each image file in your resources, then referencing this in the Image. This effectively means that each image is only loaded once from disk, rather than 2*N times (where N is the number of items in your list.)

提交回复
热议问题