TextBox控件获得焦点后,一般点击空白处还是会保留焦点的,如果在外层套一个ScrollViewer,则点击空白处会失焦;
类似NumericUpDown的控件,默认的UpdateSourceTrigger方式为LostFocus,长按NumericUpDown的增减按钮,中间的变化过程不会触发更新,若修改为PropertyChanged方式触发,在输入值有上下限时,则无法手修改输入框内的值,两者不可兼得;
可以利用Slider控件作为中间人,实现PropertyChanged的触发,TextBox的Text绑定Slider上Value,实现LostFocus触发:
<StackPanel Width="75"
Height="30"
IsEnabled="{Binding Enabled}"
Orientation="Horizontal">
<Slider x:Name="jSlider"
Maximum="{Binding MaxJ}"
Minimum="{Binding MinJ}"
Visibility="Hidden"
Value="{Binding JValue, Mode=TwoWay}" />
<RepeatButton Width="15"
Command="{Binding JDecreaseCommand}"
Content="-" />
<TextBox Width="30" Text="{Binding ElementName=jSlider, Path=Value, Mode=TwoWay}" />
<RepeatButton Width="15"
Command="{Binding JIncreaseCommand}"
Content="+" />
</StackPanel>