HowTo: Add Items Programatically to RadCarouselPanel ?

8 posts, 1 answers
  1. David Lino
    David Lino avatar
    13 posts
    Member since:
    Apr 2010

    Posted 13 May 2010 Link to this post

    Hi,I'm trying to add Items to a RadCarouselPanel through Code, But I'm having trouble...

    This is my code:

    ...
               
                <telerik:RadCarouselPanel Name="imgPicker"  ItemsMovementAnimationDuration="0:0:0.5"
                        ItemsPerPage="11" PathPadding="70,50,70,50" IsOpacityEnabled="True"
                        IsScalingEnabled="True" IsSkewAngleYEnabled="True" Height="100" MinHeight="100" >
                    <telerik:RadCarouselPanel.Path>
                        <Path HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Fill" Data="M 0,300 C0,300 500,300 500,300 " />
                    </telerik:RadCarouselPanel.Path>
                    <telerik:RadCarouselPanel.SkewAngleYStops>
                        <telerik:PathStopCollection>
                            <telerik:PathStop PathFraction="0.15" Value="-15" />
                            <telerik:PathStop PathFraction="0.45" Value="-15" />
                            <telerik:PathStop PathFraction="0.5" Value="0" />
                            <telerik:PathStop PathFraction="0.55" Value="15" />
                            <telerik:PathStop PathFraction="0.85" Value="15" />
                        </telerik:PathStopCollection>
                    </telerik:RadCarouselPanel.SkewAngleYStops>
                    <telerik:RadCarouselPanel.ScaleStops>
                        <telerik:PathStopCollection>
                            <telerik:PathStop PathFraction="0.4" Value="1.0" />
                            <telerik:PathStop PathFraction="0.5" Value="1.5" />
                            <telerik:PathStop PathFraction="0.6" Value="1.0" />
                        </telerik:PathStopCollection>
                    </telerik:RadCarouselPanel.ScaleStops>
                    <telerik:RadCarouselPanel.OpacityStops>
                        <telerik:PathStopCollection>
                            <telerik:PathStop PathFraction="0.0" Value="0.0" />
                            <telerik:PathStop PathFraction="0.1" Value="1.0" />
                            <telerik:PathStop PathFraction="0.9" Value="1.0" />
                            <telerik:PathStop PathFraction="1.0" Value="0.0" />
                        </telerik:PathStopCollection>
                    </telerik:RadCarouselPanel.OpacityStops>
                </telerik:RadCarouselPanel>           
    ...

    And my CodeBehind:

    public MainWindow ()
            {
                InitializeComponent();
               
                imageList = new List<BitmapImage>();

                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(@"Imgs/OCR1.TIF", UriKind.RelativeOrAbsolute);
                bi.EndInit();
               
                imageList.Add(bi);

                bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(@"Imgs/OCR2.TIF", UriKind.RelativeOrAbsolute);
                bi.EndInit();

                imageList.Add(bi);

                bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(@"Imgs/OCR3.TIF", UriKind.RelativeOrAbsolute);
                bi.EndInit();

                imageList.Add(bi);

                imgPicker.DataContext = imageList;

             
            }

    Is this the right way to do this?

    My panel is not showing anything =/
  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 13 May 2010 Link to this post

    Hi David Lino,

    RadCarouselPanel has a Children property which is a collection of all children that are displayed by the panel. You can use the Add method of Children to add items to RadCarouselPanel.


    Best wishes,
    Milan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David Lino
    David Lino avatar
    13 posts
    Member since:
    Apr 2010

    Posted 13 May 2010 Link to this post

    But I can't add a "BimapImage" to this collection. I Get an exception =/

    I Tried something like:

    foreach (BitmapImage bim in imageList)
                    imgPicker.Children.Add(bim);

    But I get this at compile-time:
    Error   3   Argument 1: cannot convert from 'System.Windows.Media.Imaging.BitmapImage' to 'System.Windows.UIElement' 

    And I tried to cast, but was unsucessful, and doesn't have a method to do this.

    Thanks a lot!




  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 13 May 2010 Link to this post

    Hi David Lino,

    Only UIElements can be added to this collection. You can use Image objects instead of BitMapImage.


    All the best,
    Milan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. David Lino
    David Lino avatar
    13 posts
    Member since:
    Apr 2010

    Posted 13 May 2010 Link to this post

    I Tried to use Images, but I was unsucessful =/

    This is my Code:

    imageList = new List<Image>();
                
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(@"Imgs/img.TIF", UriKind.RelativeOrAbsolute);
                bi.EndInit();
                imageList.Add(new Image { Source = bi } );

                bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(@"Imgs/img2.TIF", UriKind.RelativeOrAbsolute);
                bi.EndInit();

                imageList.Add(new Image { Source = bi });

                bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(@"Imgs/img3.TIF", UriKind.RelativeOrAbsolute);
                bi.EndInit();

                imageList.Add(new Image { Source = bi });

                foreach (Image bim in imageList)
                    imgPicker.Children.Add(bim);

  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 14 May 2010 Link to this post

    Hello David Lino,

    I am sending you a sample project that achieves the desired result of adding images to RadCarouselPanel through code. 
    I hope that helps.


    Sincerely yours,
    Maya
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. David Lino
    David Lino avatar
    13 posts
    Member since:
    Apr 2010

    Posted 17 May 2010 Link to this post

    HI, thanks

    It worked!

    Where can I Find classes documentation, descripting members, properties and events from RADWPF classes like radCarousel? The .chm from the site doesn't have these things =/
  9. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 May 2010 Link to this post

    Hello David Lino,

    You can find detailed information about all RadControls, including RadCarousel, in our online documentation.  Furthermore, here you will find details about the namespaces, members, etc of RadCarousel.

    Kind regards,
    Maya
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for WPF is Visual Studio 2017 Ready