将滑块绑定到另一个滑块WPF [英] Binding slider to another slider WPF

查看:68
本文介绍了将滑块绑定到另一个滑块WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有20个滑块,如果我更改1个滑块的值,则应更改剩余的19个滑块值。那么如果我更改了18个滑块值会更改。剩下的滑块请帮帮我吗?

I have 20 sliders, If I change 1 slider's value then remaining 19 slider value should changed. then if i changed 18 slider value will change.same for remaining slider please help me?

推荐答案

这不是问题,你'我只是坚持定义你的项目的逻辑。你需要的是所谓的Binding,除了数据绑定,你可以将一个控件的属性绑定到其他控件;比如滑块上的Value到其他Slider的Value属性等等。



在继续之前,请阅读有关 MSDN上的数据绑定 [ ^ ],它们将为您提供足够的潜在理解,了解它的实际用途,何时应该使用它,以及它为您提供了什么。您将成为MSDN文档的好公司。



从我的这个例子中你可以理解如何做到这一点。我将使用2个滑块(而不是20个),我将第二个值绑定到第一个值。看下面,



This is not a problem, you're just stuck defining the logic of your project. What you need is known as Binding, apart from data binding, you can bind properties of one control to other; such as Value of on Slider to the Value property of other Slider and so on.

Before you continue, please read the documentation about Data binding on MSDN[^], they would provide you enough underlying understanding of what this is in real, when you should use it, and what does it provide you with. You will be in a good company on MSDN documentations.

You can understand how to do this, from this example of mine. I will use 2 sliders (not 20) and I will bind value of second, to the value of first one. Look below,

<Slider Name="slider1" Minimum="0" Maximum="100" />
<Slider Value="{Binding ElementName=slider1, Path=Value}" Minimum="0" Maximum="100" />





现在,当您更改第一个滑块的值时,第二个会自动改变;因为它现在绑定到 slider1 。了解有关 MSDN上的滑块控件 [ ^ ]。然后,您可以使用相同的机制将其他控件绑定到彼此。



Now when you will change the value of first slider, the value of the second one would change automatically; because it is now bound to the slider1. Learn more about Slider controls on MSDN[^]. You can then use the same mechanism to bind other controls to each other.


这篇关于将滑块绑定到另一个滑块WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆