Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6829157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:28:00+00:00 2026-05-26T22:28:00+00:00

I have a listbox that I am trying to build a triggeraction for. Basically

  • 0

I have a listbox that I am trying to build a triggeraction for. Basically I would like my triggeraction to be triggered when ItemsSource or Items is updated. I tried using both PropertyChangedTrigger and DataStoreChangedTrigger. The problem is that when either of these triggers gets executed my ItemsSource is empty at that time. So the question is what event can I hook into to know when my ItemsSource is changed? I am using the mvvm pattern and therefore cannot have any code behind. Here’s some code

<ListBox x:Name="commentaryViewItems" 
        VirtualizingStackPanel.IsVirtualizing="False" 
        Background="White" 
        ItemsSource="{Binding CommentaryItemViewsModels}">
<iy:Interaction.Triggers>
    <is:DataStoreChangedTrigger Binding="{Binding Path=ItemsSource, ElementName=commentaryViewItems}">
        <localBehaviors:AutoScrollingTargetedTriggerAction></localBehaviors:AutoScrollingTargetedTriggerAction>
    </is:DataStoreChangedTrigger>                                        
</iy:Interaction.Triggers>
<ItemsControl.ItemTemplate>
    <DataTemplate>
        <local:CommentaryItemView DataContext="{Binding}"></local:CommentaryItemView>
    </DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>



public class AutoScrollingTargetedTriggerAction : TriggerAction<ListBox>
{
protected override void Invoke(object parameter)
{
    ListBox items = AssociatedObject as ListBox;

    if (items != null)
    {
        ItemCollection commentaryItemViewModels = items.Items;

        if (commentaryItemViewModels != null)
        {
            IList<ICommentaryItemViewModel> viewModels = new List<ICommentaryItemViewModel>();
            foreach (var viewModel in commentaryItemViewModels)
            {
                ICommentaryItemViewModel currentViewModel = viewModel as ICommentaryItemViewModel;
                if (currentViewModel != null)
                    viewModels.Add(currentViewModel);
            }

            if (viewModels.Count > 0)
            {
                // if there is more than one date header go to first one and move scroll to there
                if (viewModels.Count(c => c.IsTitleBarVisible == true) > 1)
                {
                    // get first viewmodel with header
                    ICommentaryItemViewModel viewModel =
                        viewModels.FirstOrDefault(f => f.IsTitleBarVisible == true);
                    if (viewModel != null)
                        items.ScrollIntoView(viewModel.View);
                }

                // if there is only one header move scroller to last item
                if (viewModels.Count(c => c.IsTitleBarVisible == true) == 1)
                {
                    ICommentaryItemViewModel viewModel =
                        viewModels.FirstOrDefault(f => f.IsTitleBarVisible == true);
                    if (viewModel != null)
                        items.ScrollIntoView(viewModel.View);
                }
            }
        }
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:28:01+00:00Added an answer on May 26, 2026 at 10:28 pm

    I was using an observablecollection. The problem is that I’m trying to scroll my listbox based on the items contained within it. So at the time that the observablecollection changes it is not necessarily the time that the listbox has been updated. What I ended up doing is hooking into a click button that I had below and that seems to be occuring at the appropriate time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a ListBox with items that have edit states. I
I have a listbox that displays Shipment Items (custom class) that are formatted using
I have a ListBox that I bind to an ItemsSource, like this: var foos
I have a ListBox that during development I had the items in the ListBox
I'm trying to remove some objects from a ListBox that I have created, and
I have a listbox that is populated with a list of List items. The
I have a ListBox that has a style defined for ListBoxItems. Inside this style,
I have a listbox that is databound to a Collection of objects. The listbox
I have a ListBox that when in focus, and when I have an item
I have a ListBox that is bound to a list of Persons. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.