The use of ContentPropertyAttribute in TransitionControl

2 posts, 0 answers
  1. Sandi Markon
    Sandi Markon avatar
    101 posts
    Member since:
    Jul 2012

    Posted 08 Nov 2010 Link to this post

    The thing is, i want to be able to add custom user controls to the TransitionControl. Something like...

           
    <local:CardControl>
        <Button Content="Hello" />
        <Button Content="Hello" />
    </local:CardControl>


    ...and to be able to implement custom transition logic inside the inherited class.

    Now, the class CardControl inherits from RadTransitionControl, like shown below:

         [ContentProperty("Items")]
        [ContentWrapper(typeof(Collection<UIElement>))]
        public class CardControl : RadTransitionControl
        {
            public static readonly DependencyProperty ItemsProperty =
                DependencyProperty.Register("Items", typeof(Collection<UIElement>),
                     typeof
    (CardControl), new FrameworkPropertyMetadata(new Collection<UIElement>(),
    FrameworkPropertyMetadataOptions.AffectsRender
    , OnItemsChanged));
                                   
     
     public Collection<UIElement> Items
     {
        get { return (Collection<UIElement>)GetValue(ItemsProperty); }
        set
            {
              SetValue(ItemsProperty, value);
            }
     }
           
            public CardControl()
            {
                
            }
     
            private static void OnItemsChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
            {
                (dependencyObject as CardControl).Content = (eventArgs.NewValue as Collection<UIElement>)[0];
            }
        }

    As you can see, I've added the ContentPropertyAttribute, which in turn, should allow the user to add items in XAML, and store them in the Items property. It works, if i use a single item, but it shows no reaction, when i try to use the collection of UIElements.

    Any ideas on how to make it work?
    Thanks,
  2. Sandi Markon
    Sandi Markon avatar
    101 posts
    Member since:
    Jul 2012

    Posted 09 Nov 2010 Link to this post

    I've figured it out. The OnItemsChanged callback didn't fire, when the number of items changed in the collection, so I used the CollectionChanged event of the ObservableCollection<UIElement>, and it went smoothly :)
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top