简体   繁体   English

滑块控件WPF的EventSetter

[英]EventSetter for Slider Control WPF

Tried to write an EventSetter for 4 slide controls but it doesn't work. 试图为4个滑动控件编写一个EventSetter,但是它不起作用。 Keeps giving me error ie 'FourthProject.MainWindow' does not contain a definition for 'slider_ValueChanged' and no extension method 'slider_ValueChanged' accepting a first argument of type 'FourthProject.MainWindow' could be found (are you missing a using directive or an assembly reference?) 不断给我错误,即'FourthProject.MainWindow'不包含'slider_ValueChanged'的定义,并且找不到扩展方法'slider_ValueChanged'接受类型为'FourthProject.MainWindow'的第一个参数(是否缺少using指令或程序集参考?)

This is what I tried: 这是我尝试的:

<EventSetter Event="Slider.ValueChanged"
Handler="slider_ValueChanged" />

Here is the code behind 这是背后的代码

private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { SolidColorBrush backgroundColor = new SolidColorBrush(); 私人无效Slider_ValueChanged(对象发送者,RoutedPropertyChangedEventArgs e){SolidColorBrush backgroundColor = new SolidColorBrush(); backgroundColor.Color = Color.FromArgb((byte)alphaSlider.Value (byte)redSlider.Value, (byte)greenSlider.Value, (byte)blueSlider.Value); backgroundColor.Color = Color.FromArgb((byte)alphaSlider.Value(byte)redSlider.Value,(byte)greenSlider.Value,(byte)blueSlider.Value);

        // set colorLabel's background to new color
        colorLabel.Background = backgroundColor;
    }

Please help I am new to WPF and its quite confusing. 请帮助我是WPF的新手,它相当令人困惑。 Thanks 谢谢

XAML is just fine: XAML很好:

<EventSetter Event="Slider.ValueChanged" Handler="Slider_ValueChanged"/>

You just need to properly define your handler (code behind): 您只需要正确定义您的处理程序(后面的代码)即可:

public void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    MessageBox.Show("Value Changed: " + e.NewValue.ToString());
}

Maybe you have a DataContext set on your root element or your event handler isn't public. 也许您在根元素上设置了DataContext或事件处理程序不是公开的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM