Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WPF
  4. scroll ListBox to bottom in xaml

scroll ListBox to bottom in xaml

Scheduled Pinned Locked Moved WPF
wpfdesignarchitecturehelpcsharp
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ausadmin
    wrote on last edited by
    #1

    I have been using the MVVM pattern extensively to build a UI (as in the great samples "WPF Apps With The Model-View-ViewModel Design Pattern"[^] and "Creating an Internationalized Wizard in WPF" [^]. This is a great technique for UI development, and I thank Josh Smith and Karl Shifflett for their postings and assistance in this area. While I have now got most of this working really well, I have hit a problem that I can't figure out how to solve in xaml or with data binding. I have a ListBox which I can add items to, but as the number of items exceeds the size of the ListBox, the items added at the bottom scroll out of view... I want to have the ListBox automatically scroll to display the last item. Can anyone tell me how to do this in xaml? I have reviewed several posts regarding use of the ScrollIntoView method, but I do not know how to access this from xaml (I think it may not be possible as its a method). As this is using the MVVM pattern, there is no way (that I am aware of) to access the ListBox instance from the code, to be able to call ScrollIntoView. Another solution would be to scroll to item n in xaml, which would be fine because I could then data bind to n. However I also have not been able to find a way to control the scrolling in xaml. I'm realy surprised there seems to be no easy way to do this in xaml. Any help would be greatly appreciated. Thanks, Tim

    L 1 Reply Last reply
    0
    • A ausadmin

      I have been using the MVVM pattern extensively to build a UI (as in the great samples "WPF Apps With The Model-View-ViewModel Design Pattern"[^] and "Creating an Internationalized Wizard in WPF" [^]. This is a great technique for UI development, and I thank Josh Smith and Karl Shifflett for their postings and assistance in this area. While I have now got most of this working really well, I have hit a problem that I can't figure out how to solve in xaml or with data binding. I have a ListBox which I can add items to, but as the number of items exceeds the size of the ListBox, the items added at the bottom scroll out of view... I want to have the ListBox automatically scroll to display the last item. Can anyone tell me how to do this in xaml? I have reviewed several posts regarding use of the ScrollIntoView method, but I do not know how to access this from xaml (I think it may not be possible as its a method). As this is using the MVVM pattern, there is no way (that I am aware of) to access the ListBox instance from the code, to be able to call ScrollIntoView. Another solution would be to scroll to item n in xaml, which would be fine because I could then data bind to n. However I also have not been able to find a way to control the scrolling in xaml. I'm realy surprised there seems to be no easy way to do this in xaml. Any help would be greatly appreciated. Thanks, Tim

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Tim, Please have a look a Josh's article on Attached Behaviors. http://joshsmithonwpf.wordpress.com/2008/08/30/introduction-to-attached-behaviors/[^]

      Cheers, Karl » CodeProject 2008 MVP, CodeProject 2009 MVP My Blog | Mole's Home Page | XAML Power Toys Home Page

      Just a grain of sand on the worlds beaches.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups