Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
[very urgent] Index of the clicked item
posted

Hi, i have this UserControl, using xamcarouselpanel.

 

I need to bring in the middle of the path one of the carousel items (a button or similar) when the user clicks it.

 I need the Index of the item the user clicks, so I can do some calculations.

following the xaml and the c#:

 

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="MovingCarousel.MainMenu"
    x:Name="UserControl"
    d:DesignWidth="640" d:DesignHeight="480" xmlns:igWindows="http://infragistics.com/Windows">

    <Grid x:Name="LayoutRoot">
            
        <igWindows:XamCarouselPanel x:Name="MainCarouselPanel" Margin="0,0,0,20">    
            <igWindows:XamCarouselPanel.ViewSettings>
                <igWindows:CarouselViewSettings
                        
                        UseOpacity="True"
                        IsListContinuous="True">
                </igWindows:CarouselViewSettings>
            </igWindows:XamCarouselPanel.ViewSettings>
            
            <!-- contenuto -->
            <Button x:Name="b1" Content="b1" Click="ButtonaAll_Click"/>
            <Button x:Name="b2" Content="b2" Click="ButtonaAll_Click"/>
            <Button x:Name="b3" Content="b3" Click="ButtonaAll_Click"/>
            <Button x:Name="b4" Content="b4" Click="ButtonaAll_Click"/>
            <Button x:Name="b5" Content="b5" Click="ButtonaAll_Click"/>
            <!-- /contenuto -->
            
        </igWindows:XamCarouselPanel>
    </Grid>
</UserControl>

 

using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using Infragistics.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

namespace MovingCarousel
{
    public partial class MainMenu
    {

        public MainMenu()
        {
            this.InitializeComponent();
            // Insert code required on object creation below this point.
        }

        private void ButtonaAll_Click(object sender, RoutedEventArgs e)
        {
            CarouselViewSettings viewSettings = this.MainCarouselPanel.ViewSettings;
            int centerOffset = viewSettings.ItemsPerPage / 2;;
            int rem;
           
            Math.DivRem(viewSettings.ItemsPerPage, 2, out rem);
            if (rem > 0)
                centerOffset++;

            MainCarouselPanel.SetVerticalOffset(MainCarouselPanel.ChildElements.IndexOf((Button)sender) - centerOffset + 1);
        }
    }
}
 

 

p.s. I tried with  MainCarouselPanel.ChildElements.IndexOf((Button)sender) but it returns always "-1". Please help me, it's very urgent..

  • 9694
    posted

    By the way, I apologize that an Infragistics engineer could not answer this post in an urgent manner. Next time, please use our developer support services for urgent matters. The forums are a more relaxed place to interact with other users and Infragistics engineers. As a result, an engineer may not get to an unanswered post right away. Our DS team on the other hand will try to solve your issue right away.

    Developer Support:
    http://es.infragistics.com/support/ask-for-help.aspx

    Thank you,

  • 9694
    posted

    Please look at a blog I wrote about how to scroll an item in the carousel to the front (a specific position) when selecting the item.

    http://blogs.infragistics.com/blogs/ctaylor/default.aspx

    Let me know if this helps.

    Also, the reason the IndexOf method is returning -1 is because you need to get the CarouselPanelItem container object which is being created for the container for the item in the carousel behind the scenes. If the Button is one of the child elements in the Carousel, it should be safe to check it's parent owner property. You can use the CarouselPanelItem to get the correct index.