This is a migrated thread and some comments may be shown as answers.

The use of ContentPropertyAttribute in TransitionControl

1 Answer 123 Views
TransitionControl
This is a migrated thread and some comments may be shown as answers.
Sandi Markon
Top achievements
Rank 1
Sandi Markon asked on 08 Nov 2010, 01:37 PM
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,

1 Answer, 1 is accepted

Sort by
0
Sandi Markon
Top achievements
Rank 1
answered on 09 Nov 2010, 08:19 AM
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 :)
Tags
TransitionControl
Asked by
Sandi Markon
Top achievements
Rank 1
Answers by
Sandi Markon
Top achievements
Rank 1
Share this question
or