我在wpf中遇到以下问题:
我已经定义了一个包含文本框的用户控件(在命名空间测试中)(以及其他几个控件,只显示了xaml的相关部分):
<UserControl (...)
DataContext="{Binding RelativeSource={RelativeSource Self}}"
name="Spinbox">
(...)
<StackPanel Orientation="Horizontal">
<TextBox x:Name="tbText" (...)>
<TextBox.Text>
<Binding Path="Value" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local:ValidateValue MinVal="0" MaxVal="1" />
</Binding.ValidationRules>
<Binding.NotifyOnValidationError>true</Binding.NotifyOnValidationError>
</Binding>
</TextBox.Text>
</TextBox>
(...)
Run Code Online (Sandbox Code Playgroud)
在主窗口文件中,我正在使用此spinbox:
<Test:SpinBox x:Name="tbTestSpinbox" Value="{Binding Path=TheValue}"
MinValue="0" MaxValue="150">
<Test:SpinBox.Behavior>
<Controls:SpinBoxNormalBehavior />
</Test:SpinBox.Behavior>
</Test:SpinBox>
Run Code Online (Sandbox Code Playgroud)
在后面的代码中,我定义了TheValue:
private double theValue;
public Window1()
{
InitializeComponent();
TheValue = 10;
}
public double TheValue
{
get { return theValue; }
set
{
theValue = value;
NotifyPropertyChanged("TheValue");
}
}
/// <summary>
/// Occurs when a property value changes
/// …Run Code Online (Sandbox Code Playgroud)