我试过这个 XAML:
<Slider Width="250" Height="25" Minimum="0" Maximum="1" MouseLeftButtonDown="slider_MouseLeftButtonDown" MouseLeftButtonUp="slider_MouseLeftButtonUp" />
而这个 C#:
private void slider_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
sliderMouseDown = true;
}
private void slider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
sliderMouseDown = false;
}
sliderMouseDown 变量永远不会改变,因为永远不会引发 MouseLeftButtonDown 和 MouseLeftButtonUp 事件。当用户在滑块上按下鼠标左键以将 bool 值设置为 true 并且当鼠标向上时 bool 设置为 false 时,如何让此代码工作?