我有一个滑块,我在内部更新值。而且,用户输入被接受,以改变内部参数。如何知道谁在WPF中引发了路由事件?
问题是:我怎么能知道谁提出了事件,用户或我更改slider.value的类?
在我而言,这是处理程序:
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
var slider = sender as Slider;
if (slider == null) return;
var col = this.SelectedColor;
switch ((string)slider.Tag)
{
case "Hue": this.SetHue(ValueHue.Value); break;
case "Sat": this.SetSatBri(ValueSat.Value, CurrentBri); break;
case "Bri": this.SetSatBri(CurrentSat, ValueBri.Value); break;
case "R": this.SetColor(Color.FromRgb(Convert.ToByte(ValueR.Value), col.G, col.B)); break;
case "G": this.SetColor(Color.FromRgb(col.R, Convert.ToByte(ValueG.Value), col.B)); break;
case "B": this.SetColor(Color.FromRgb(col.R, col.G, Convert.ToByte(ValueB.Value))); break;
}
}
如果事件不是由用户输入所提出的功能不能正常工作。那么我怎么能找到这个呢?
您是否尝试过'e.OriginalSource' – mihajlv 2011-12-31 22:42:38