Skip to main content

Microsoft Silverlight

Unanswered Question Dependency property - FrameworkElementRSS Feed

(0)

Herthoren
Herthoren

Member

Member

85 points

82 Posts

Dependency property - FrameworkElement

Hi!

 

Have a similar question, but that's fundamentally about a different issue.

While trying to solve it, realized that in Silverlight trying to set a Dependency Property from XAML to a FrameworkElement will always throw an exception.

I can set it even from Blend fully through the UI, it stil won't work.

 

In the same ControlTemplate:

<ContentControl Content="{StaticResource Pic}"/>

This works perfectly, the picture is displayed.

 

<Setter Property="IMDP" Value="{StaticResource Pic}"/>

This line drops a nullreference exception (IMDP is a legit dependency property of FrameworkElement type).

 

Noticed that ContentControl's Content property is an object so tried changing the dp type, tried FrameworkElement, object, Image, nullreference exception for all.

 

 

So Silverlight FrameworkElement dependency properties cannot be set from xaml?

Is this a bug? A known limitation? Is there a workaround?

Couldn't really find anything about it, only seen that it works in WPF.

 

Thank you

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7178 points

1,340 Posts

Re: Dependency property - FrameworkElement

Hi,

Hm.., strangely How do you declare a dependency property and how do you use it?

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

Herthoren
Herthoren

Member

Member

85 points

82 Posts

Re: Dependency property - FrameworkElement

Define this way:

        public FrameworkElement Pic { get { return (FrameworkElement)GetValue(PicProperty); } set { SetValue(PicProperty, value); } }
        public static readonly DependencyProperty PicProperty = DependencyProperty.Register("Pic", typeof(FrameworkElement), typeof(ArenaUIWindow), null);

 

Set this way:

<Setter Property="Pic" Value="{StaticResource PicRes}"/>

 

Usage is irrelevant since when I set a breakpoint at OnApplyTemplate, it shows that the value is null, while in other cases where the dp is not a frameworkelement, they are all set.

 

BTW, as I wrote in my other question, I can set it the following way:

    <Setter Property="Pic">
        <Setter.Value>
            <Image Width="40" Height="40" Source="/ArenaUIWindowAssembly;Component/Images/pic1.png"/>
        </Setter.Value>
    </Setter>  

 

Problem with this method is that I can't add it to a canvas, I believe due to the reason described here:

http://forums.silverlight.net/forums/p/117697/264939.aspx

 

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7178 points

1,340 Posts

Re: Dependency property - FrameworkElement

Can do you show a definition of PicRes resource?

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

Herthoren
Herthoren

Member

Member

85 points

82 Posts

Re: Dependency property - FrameworkElement

     <Image x:Key="PicRes" Height="40" Width="40" Source="/ArenaUIWindowAssembly;Component/Images/pic1.png"/>

 

(defined in the same resource dictionary as the controltemplate)

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities