Silverlight / WPF - Refresh of WPF controls

Asked By Jim Bassett
28-Sep-09 04:41 PM

This appears to be an issue with all the WPF controls but the one I am working with at the moment is the ListView control. In a loop I call a method that preforms some things and then adds an item to a ListView. The loop might add from 2 to 20 items to the listView control but they don't appear until after the loop is finished. There is no Refresh property so is there a way to have the ListView controlFresh after each item is added?

  web mavin replied to Jim Bassett
28-Sep-09 10:34 PM

Try doing lstMyListView.Items.Rerfresh();

And in case if you are binding it viz LINQ, then refer: http://blog.bksanders.com/index.php/2008/09/wpf-listview-not-refreshing/

But as I see your question, you are simply adding the items in a loop without using observablecollection or so right..? So, you would be able to see the UI properly after all the items are added..won't u? What's the exact scenario otherwise?

One has to use a BackgroundWorker  One has to use a BackgroundWorker

30-Sep-09 11:11 AM
 

Below is a VB.NET Window ContentRendered event. The contents of the list box that is being filled does not appear until the loop is finished and this event is retruned. To have the List View or Listbox or any WPF UI control show the content as it is being added one must use a BackgroundWorker (see http://dotnet.org.za/rudi/archive/2009/01/19/wpf-basics-loading-large-datasets.aspx)  So to get the WPF based listbox to show the items as they are added the loop has to be in its own method and called from the ContetnRendered event. A thread is required just to fill and view a listbox or Listview  items as they are added. What a pain.

This requirement is not RAD and I assume it has to do with the view model of WPF. I also find it troublesome that this requirement is not oblivious.

Private Sub Window2_ContentRendered(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ContentRendered

Dim strItem As String

Dim i As Integer

i = 1

While i < 10000

   strItem = "Document # " + i.ToString() + " added"

   ListBox1.Items.Add(strItem) ' The item is added but does not appear

   ListBox1.Items.Refresh() ' Doing the refresh does not make the item appear either.

   i = i + 1

End While

End Sub

You should be using the Dispatcher object from App.Current  You should be using the Dispatcher object from App.Current

30-Sep-09 02:29 PM
This is equivalent to the DoEvents of winforms.

And here is the modified code. 
Private Sub Window2_ContentRendered(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ContentRendered

Dim strItem As String
Dim i As Integer

i = 1

While i < 10000

strItem = "Document # " + i.ToString() + " added"
  Dim listBoxItem As New ListBoxItem()
  listBoxItem.Content = strItem
  ListBox1.Items.Add(listBoxItem);
  App.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Loaded,        DirectCast(Function() Do End Function, Action))
  i += 1
End While

End Sub

Note: There could be a syntax error on the line in brown.
Create New Account
help
SilverLight What is SilverLight, its concept, why to use it and how to use it What is Silverlight? Silverlight is a new cross-browser, cross-platform implementation of the .NET Framework for building and browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, Opera. The plugin required to run Silverlight is very small in size hence gets installed very quickly. It is combination of different platform that allows you to select tools and the programming language you want to use. Silverlight integrates seamlessly with your existing Javascript and ASP.NET AJAX code to complement functionality which you have already created. Silverlight aims to compete with Adobe Flash and the presentation components of Ajax . It also competes with Sun Microsystems' JavaFX, which was launched a few days after Silverlight. Currently there are 2 versions of Silverlight: Silverlight 1.0 : Silverlight 1.0 consists of
silverlight and wpf difference if one person has gain master in silverlight than wiil this help him in learning wpf Hi Malik, WPF has a more advanced and mature XAML support than Silverlight. Silverlight used to be called (WPF / E) and is a subset of the WPF XAML design well and other items. WPF is hardware accelerated and supports things like GPU shaders which Silverlight 2 does not. Silverlight 2 does have the VisualStateManager inside Blend 2, which I think WPF needs an add on and a tweak to work. I think that is the only case where Silverlight 2 XAML was / is slightly ahead of WPF's. Here is a link on XAML us / library / cc917841(VS.95).aspx Here is a good article on MSNMAG about designing Silverlight / WPF apps together and sharing code: http: / / msdn.microsoft.com / en-us / magazine / cc895632.aspx
View HTML files in silverlight Silverlight / WPF hi. . how to View HTML files in silverlight? via silverlight how to disable the right click option in html files? i.e)SL html viewer no, status = no, menubar = no, resizable = yes"); } } } Create New Account keywords: View, HTML, files, in, silverlight description: p style = border:0px;margin-bottom: 18px; border-image: initial; outline-width: 0px; outline
Silverlight What is the purpose of Silverlight? Why it is used? How can I use silverlight in my application? Any simple web example of silverlight with VS 2005 and .Net Framework 2.0 (not the Hellow world Application). ? I want to start with Silverlight and I am very new to Silverlight. What is Silverlight? Microsoft Silverlight is a web browser plugin that provides support for rich internet applications such as animation
Load swf files in silverlight Silverlight / WPF hi. . how to Load swf file in silverlight? need ur suggetsions with examples. . regards gopal.s There is a swf to xaml converter available http: / / theconverted.ca / And there are some silverlight carousel examples available http: / / silverlight.net / learn / learnvideo.aspx?video = 33734 Refer this link- http: / / forums silverlight.net / t / 79400.aspx Hi, As per my knowledge, you can not load the swf file directly to silverlight, you need to convert swf to silverlight format first. here are some useful links that help to convert the swf into your