Skip to main content

Microsoft Silverlight

Answered Question How to Fix 'cannot convert from 'System.Windows.PropertyChangedCallback' to 'System.Windows.PropertyMetadata' ?RSS Feed

(0)

dbaechtel
dbaechtel

Member

Member

59 points

207 Posts

How to Fix 'cannot convert from 'System.Windows.PropertyChangedCallback' to 'System.Windows.PropertyMetadata' ?

I am trying to build Delay's sample from "Lying to the layout system for a good cause [Bringing LayoutTransform to Silverlight 2!]" and I get 7 errors when building with VSTS 2008 SP1. Six of the errors are from code like the following:

private static void ChildChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
...
}

 public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
    "Child", typeof(FrameworkElement), typeof(LayoutTransformControl), new PropertyMetadata(ChildChanged));

The problem stems from the type conversion of the ChildChanged parameter to  PropertyMetadata.
This follows then MSDN documentation.

Does anyone know how to fix this?

THANKS MUCH.

Skyrunner
Skyrunner

Contributor

Contributor

2489 points

485 Posts

Silverlight MVP
Answered Question

Re: How to Fix 'cannot convert from 'System.Windows.PropertyChangedCallback' to 'System.Windows.PropertyMetadata' ?

Replace by

new PropertyMetadata(new PropertyChangedCallback(ChildChanged))

Bill Reiss
Bill Reiss

Contributor

Contributor

4840 points

919 Posts

Silverlight MVP

Re: How to Fix 'cannot convert from 'System.Windows.PropertyChangedCallback' to 'System.Windows.PropertyMetadata' ?

For a bit of background, this was changed from Beta 1 to Beta 2, the new format is consistent with WPF. The suggestion above is correct.


Bill Reiss, Coauthor of Hello! Silverlight 3
My blog (rss feed)

dbaechtel
dbaechtel

Member

Member

59 points

207 Posts

Re: How to Fix 'cannot convert from 'System.Windows.PropertyChangedCallback' to 'System.Windows.PropertyMetadata' ?

Skyrunner:

Replace by

new PropertyMetadata(new PropertyChangedCallback(ChildChanged))

 

That didn't work.

I changed it to:

        public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
            "Child", typeof(FrameworkElement), typeof(LayoutTransformControl), new PropertyMetadata(new PropertyChangedCallback(ChildChanged)));

 

and still getting the same error:

Error 2 Argument '4': cannot convert from 'System.Windows.PropertyChangedCallback' to 'System.Windows.PropertyMetadata' 

dbaechtel
dbaechtel

Member

Member

59 points

207 Posts

Re: How to Fix 'cannot convert from 'System.Windows.PropertyChangedCallback' to 'System.Windows.PropertyMetadata' ?

I'm sorry.

I didn't notice that Delay had the following code defined:

#if SILVERLIGHT
using PropertyMetadata = System.Windows.PropertyChangedCallback;
#endif

 Once I commented that out, the fix worked fine.

 THANKS MUCH !!

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities