本文介绍了如何设置对 WPF IntegerUpDown 工具包的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个 WPF IntegerUpDown
工具包,我想为其中一个工具包设置一个限制,第二个 IntegerUpDown
工具包的最大值应等于该值第一个 IntegerUpDown
工具包.
I have two WPF IntegerUpDown
toolkit and I would like to set to one of the toolkit a restriction , the maximum of the second IntegerUpDown
toolkit should be equals to the value of the first IntegerUpDown
toolkit.
我选择 Value_changed
事件来执行此操作,但出现此异常
I choose Value_changed
event to do this , but I got this exception
System.NullReferenceException: 'Object reference not set to an instance of an object.'
这是我的代码:
private void minimumatt_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
maximumatt.Maximum = minimumatt.Value;
}
XML 代码:
<wpfToolkit:IntegerUpDown ValueChanged="minimumatt_ValueChanged" Value="0" Minimum="0" x:Name="minimumatt" MinWidth="100" />
<wpfToolkit:IntegerUpDown Value="0" Minimum="0" x:Name="maximumatt" MinWidth="100" />
如何向 IntgerUpDown
WPF 工具包控件添加限制?
How can I add a restriction to the IntgerUpDown
WPF toolkit control?
推荐答案
Is there any reason you cannot bind the Maximum
directly to the Value
of the other control?
<wpfToolkit:IntegerUpDown x:Name="minimumatt"
Value="0"
Minimum="0" />
<wpfToolkit:IntegerUpDown x:Name="maximumatt"
Value="0"
Minimum="0"
Maximum="{Binding ElementName=minimumatt,
Path=Value
UpdateSourceTrigger=PropertyChanged}" />
这篇关于如何设置对 WPF IntegerUpDown 工具包的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!