Slider On/Off Switch in WPF

前端 未结 6 696
灰色年华
灰色年华 2020-12-22 21:39

I am looking for a WPF tutorial on creating a slide ON/OFF switch like on the iPhone.

Here is an example (the "Send all traffic" option) https://secure-tunn

6条回答
  •  天命终不由人
    2020-12-22 21:47

    Well I set out to accomplish this same task but the examples fell a little short of production code. For instance what happens if you put text into the control like On/Off or a localized version of the text, answer is you have to define the size of the control because you cannot modify an animation or template triggers after you have rendered the control. This gives you a one-size-fits-all solution that will not work with localized text.

    My solution was to create the template for the control dynamically using the control's Loaded event and the FrameworkElementFactory class. I have to say it was by far complicated but could be achieved. Simply put, in your code behind, create a template as described, setup dependency properties for your on/off text, use the text metrics to determine the control's width, height and animation values.

    I'm sorry that I cannot post the solution since it belongs to Avanquest now. :(

    Look for it in SystemSuite and Fix-It 12.

提交回复
热议问题