CarouselPanel.SelectedIsTopItem event fails to notify when property changes to false

1 Answer 50 Views
Carousel
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Joe asked on 05 May 2023, 07:44 PM | edited on 10 May 2023, 01:41 AM

If I have subscribed to the RadCarouselPanel.SelectedIsTopItem event, should I not get notifications when that property changes to false?

In my case, when the user scrolls the mouse wheel over the control or hits the little left/right buttons at the bottom of the carousel, the selected item certainly moves off of the top.  But the event is never fired.  It is only fired when I left click on the item to make the control force it to the top.


To illustrate, here is how I find the panel and subscribe to the events

var panel = this.Carousel.FindChildByType<RadCarouselPanel>();
panel.IsAnimatingChanged += Panel_IsAnimatingChanged;
panel.SelectedIsTopItem += Panel_SelectedIsTopItem;


I then have debug log lines in the two handler functions to let me know when the events fire.

private void Panel_SelectedIsTopItem(object sender, RoutedEventArgs e)
{
    var panel = (RadCarouselPanel)sender;
    Log.Debug($"Panel SelectedIsTopItem changed to {panel.IsSelectedTopItem}");
}

private void Panel_IsAnimatingChanged(object sender, RoutedEventArgs e)
{
    var panel = (RadCarouselPanel)sender;
    Log.Debug($"Panel is animating changed to {panel.IsAnimating}");
}

When I bring up my display the selected item is at the top by default







Then I use the mouse wheel or the scroll buttons to move the panel items without changing the selected item.  Note that the blue "selected" rectangle still appears around #002 to the left even though it is not #003 that is topmost





But all I get in my log is IsAnimatingChanged events 

15:31:50.690 [  1] DEBUG - Panel_IsAnimatingChanged: Panel is animating changed to True
15:31:50.977 [  1] DEBUG - Panel_IsAnimatingChanged: Panel is animating changed to False


But now if I  left-click the new topmost item (#003), then it becomes selected




and I am notified that SelectedIsTopMost has changed, along with an event about IsAnimating changed even though no animation occurs in this instance

15:36:16.447 [  1] DEBUG - Panel_IsAnimatingChanged: Panel is animating changed to True
15:36:16.725 [  1] DEBUG - Panel_SelectedIsTopItem: Panel SelectedIsTopItem changed to True
15:36:16.730 [  1] DEBUG - Panel_IsAnimatingChanged: Panel is animating changed to False


In order for the event SelectedIsTopMost to be useful to me, I have to be notified about it when it becomes false.   Why am I not being told this?


For sake of completeness, here is my XAML



<tk:RadCarousel x:Name="Carousel"
    Padding="0" Margin="0"
    Grid.Row="1"
    ItemsSource="{Binding ScansView}"
    VerticalContentAlignment="Top"
    IsVisibleChanged="Carousel_OnIsVisibleChanged"
    HorizontalAlignment="{Binding HorizontalAlignment}" VerticalAlignment="{Binding VerticalAlignment}"
    >

 

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 10 May 2023, 11:09 AM

Hello Joe,

Thank you for the shared details. 

You are correct that the SelectedIsTopItem event is thrown only when the selection is changed. 

That said, you should be able to utilize the TopContainerChanged event in order to get a notification when the top container is changed and check whether it is selected by comparing the DataContext of the TopContainer and the SelectedItem of the RadCarousel. Here is what I have in mind:

private void Panel_TopContainerChanged(object sender, RoutedEventArgs e)
{
            var panel = sender as RadCarouselPanel;
            var container = panel.TopContainer as FrameworkElement;
            var selectedItem = panel.ParentOfType<RadCarousel>().SelectedItem;

            if (container != null)
            {
                var item = container.DataContext;

                if (item != selectedItem)
                {
                    // top container is not selected
                }
                else
                {
                    // top container is selected
                }
            }
}

I hope you find this helpful. Let me know, if I can be of any further assistance.

Regards,
Vladimir Stoyanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Carousel
Asked by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or