ObjectDataProvider to databind in RadCarousel ItemSource doesn't work

2 posts, 1 answers
  1. Maria Im
    Maria Im avatar
    10 posts
    Member since:
    Sep 2012

    Posted 28 Oct 2009 Link to this post

    I am trying to databing a datatable result in XAML (declarative databinding). I tried it programmatically and it does work by setting the Itemsource of my radcarousel to the datatable in code. Can you please tell me where i am going wrong with my ObjectDataProvider.

    XAML code:

    <Window x:Class="TelerikCarousel.Window1" 
        Title="Window1" Height="800" Width="800" Background="DarkBlue">  
            <ObjectDataProvider x:Key="objectDataProvider" ObjectType="{x:Type local:Window1}" MethodName="InserRow" /> 
                <RowDefinition Height="280*" /> 
                <RowDefinition Height="482*" /> 
                   <!-- removed the carousel stylings so it could be shorter but it does work --> 
      <telerik:RadCarousel Margin="19,51,22,293" Name="radCarousel1" ItemsSource="{Binding Source={StaticResource objectDataProvider}}" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > 

    c# Code:
    using System;  
    using System.Windows;  
    using System.Windows.Media;  
    using System.Windows.Shapes;  
    using System.Data.SqlClient;  
    using System.Data;  
    using Telerik.Windows.Controls;  
    namespace TelerikCarousel  
        /// <summary>  
        /// Interaction logic for Window1.xaml  
        /// </summary>  
        public partial class Window1 : Window  
            public Window1()  
                //object itemsSource = radCarousel1.ItemsSource;  
                this.radCarousel1.Loaded += new RoutedEventHandler(radCarousel1_Loaded);  
            void radCarousel1_Loaded(object sender, RoutedEventArgs e)  
                Path path = CreateLinePath();  
                RadCarouselPanel panel = this.radCarousel1.FindCarouselPanel();  
                panel.ItemsPerPage = 5;  
                panel.Path = path;  
                this.radCarousel1.ReflectionSettings.Visibility = Visibility.Visible;  
                this.radCarousel1.ReflectionSettings.Opacity = 0.5;  
            private Path CreateLinePath()  
                Path newPath = new Path();  
                PathFigureCollectionConverter figureConverter = new PathFigureCollectionConverter();  
                object geometryFigures = figureConverter.ConvertFromString("M30,347 L307.5,347");  
                PathGeometry newGeometry = new PathGeometry();  
                newPath.Stretch = Stretch.Fill;  
                BrushConverter brushConverter = new BrushConverter();  
                newPath.Stroke = (Brush)brushConverter.ConvertFromString("#FF0998f8");  
                newPath.StrokeThickness = 2;  
                newGeometry.Figures = (PathFigureCollection)geometryFigures;  
                newPath.Data = (Geometry)newGeometry;  
                return newPath;  
            //public DataSet dataset = new DataSet("MedSpaImage");  
            public DataTable dt = new DataTable("Medxx");  
            public DataTable InserRow()  
                string myConnectionstring = "";  
                if (myConnectionstring == "")  
                    myConnectionstring = "Initial Catalog=MedSpa;Data Source=4DBQR61\\IMSERVER;Integrated Security=True";  
                    SqlConnection myConnection = new SqlConnection(myConnectionstring);  
                    string myInsertQuery = "SELECT * FROM Testing";  
                    SqlCommand myCommand = new SqlCommand(myInsertQuery);  
                    myCommand.Connection = myConnection;  
                    SqlDataAdapter adapter = new SqlDataAdapter();  
                    adapter.SelectCommand = new SqlCommand(myInsertQuery, myConnection);  
                catch (Exception ex)  
                return dt;  

    I am just playing with a datable. My ultimate goal would be to be able to databind in XAML the carousel with a property of type ObservableCollection<>. Is that even possible? Thanks
  2. Answer
    Milan avatar
    1989 posts

    Posted 03 Nov 2009 Link to this post

    Hi Maria Im,

    I am sending you a sample application that demonstrates how you can bind using ObjectDataProvider. Basically you just need to change the binding of the RadCarousel element from this:

    <telerik:RadCarousel Margin="19,51,22,293" Name="radCarousel1" ItemsSource="{Binding Source={StaticResource objectDataProvider}}" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"

    Into this:

    <telerik:RadCarousel Margin="19,51,22,293" Name="radCarousel1" DataContext="{StaticResource objectDataProvider}" ItemsSource="{Binding}" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"

    Hope this helps.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft R3 2016 release webinar banner
Back to Top