locked
Custom ContentControl, content change notification? RRS feed

  • Question

  • Hi all,

    I'm building a custom control, derived from ContentControl, which is supposed to add some decoration to its Content (conceptually similar to a Border). To this purpose, I've used a template, defined in a style in generic.xaml, which contains a Canvas which in turn contains two things: a ContentControl which is template-bound to my control's Content, and the decoration.

    The decoration needs to change in both size and shape according to the size of the Content, and some properties of my custom control. I'm running into trouble because I can't find a way to be notified when the Content changes, so I can't update the decoration. In full WPF, I could override the property metadata for Content and add a notification, but as far as I can tell, this can't be done in Silverlight.

    Also, even assuming that I can somehow get notified of a change in Content, the Content is not necessarily a FrameworkElement. It could be an object, such as a string, which XAML will turn into a FrameworkElement at some point. But I need to know the size of the Content as a FrameworkElement. How do I do that in the general case?
    Thursday, December 3, 2009 11:36 AM

All replies

  • Hi all,

    I'm building a custom control, derived from ContentControl, which is supposed to add some decoration to its Content (conceptually similar to a Border). To this purpose, I've used a template, defined in a style in generic.xaml, which contains a Canvas which in turn contains two things: a ContentControl which is template-bound to my control's Content, and the decoration.

    The decoration needs to change in both size and shape according to the size of the Content, and some properties of my custom control. I'm running into trouble because I can't find a way to be notified when the Content changes, so I can't update the decoration. In full WPF, I could override the property metadata for Content and add a notification, but as far as I can tell, this can't be done in Silverlight.

    Also, even assuming that I can somehow get notified of a change in Content, the Content is not necessarily a FrameworkElement. It could be an object, such as a string, which XAML will turn into a FrameworkElement at some point. But I need to know the size of the Content as a FrameworkElement. How do I do that in the general case?

    No reply? Anyone encountered the problem?
    Tuesday, July 27, 2010 8:23 AM
  • Hello there,

    If you're using binding, you can try take a look into INotifyPropertyChanged Interface.  Below is a link:

    http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx

     

    Rochelle

    Tuesday, July 27, 2010 4:34 PM
  • ContentControl does not implement INotifyPropertyChanged.
    Wednesday, July 28, 2010 8:12 AM