GradientBrushSlider SelectedBrushChanged Event exception

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 12 years ago by Robert Knight
Version: 11.2.0552
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Avatar

Hi, I am currently using the evaluation version to experiment with the color selection tools.

I was trying to hook into the GradientBrushSlider:SelectedBrushChanged Event but this results in an ArgumentException('Handler Type is Mismatched').

I have simplified everything to the bare bones and cannot see what I'm doing wrong. I have previously used near identical code to handle the SpectrumColorPicker:SelectedColorChanged Event. I include the relevant parts from both cases below.

SpectrumColorPicker ex. Works correctly.

in MainWindow.xaml

<shared:SpectrumColorPicker SelectedColorChanged="SpectrumColorPicker_SelectedColorChanged"/>

in MainWindow.xaml.cs:

private void SpectrumColorPicker_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e)
{
   // do something
}

 

GradientBrushSlider ex. Fails withArgumentException('Handler Type is Mismatched').

in MainWindow.xaml

<shared:GradientBrushSlider SelectedBrushChanged="GradientBrushSlider_SelectedBrushChanged"/>

in MainWindow.xaml.cs file:

private void GradientBrushSlider_SelectedBrushChanged(object sender, RoutedPropertyChangedEventArgs<GradientBrush> e)
{
   // do something
}

Any thoughts appreciated.

R Knight.

Comments (3)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Robert,

The event argument is RoutedPropertyChangedEventArgs<Brush>, not RoutedPropertyChangedEventArgs<GradientBrush>.


Actipro Software Support

Posted 12 years ago by Robert Knight
Avatar

Ok, I a bit confused somewhere then. The docs say GradientBrush and if I change the signature to Brush it won't compile.

Error 143 No overload for 'GradientBrushSlider_SelectedBrushChanged' matches delegate 'System.Windows.RoutedPropertyChangedEventHandler<System.Windows.Media.GradientBrush>' 

with

<shared:GradientBrushSlider SelectedBrushChanged="GradientBrushSlider_SelectedBrushChanged"/>

and

private void GradientBrushSlider_SelectedBrushChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
   //do something
}

Some difference between the evaluation version and the full version?

Thanks again

Rob

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Robert,

I see the problem now. The RoutedEvent is defined using RoutedPropertyChangedEventArgs<Brush>, but the CLR event that wraps it uses RoutedPropertyChangedEventArgs<GradientBrush>. This will be fixed in the next maintenance release, which should be out this week.

Until then the only workaround would be to add the handler directly to the RoutedEvent in code behind, instead of using the CLR wrapper event, like so:

<shared:GradientBrushSlider x:Shared="slider" />


and

public MainWindow() {
    InitializeComponent();
    this.slider.AddHandler(GradientBrushSlider.SelectedBrushChangedEvent, new RoutedPropertyChangedEventHandler<Brush>(this.GradientBrushSlider_SelectedBrushChanged));
}

private void GradientBrushSlider_SelectedBrushChanged(object sender, RoutedPropertyChangedEventArgs<Brush> e)
{
    //do something
}


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.