ti posto una classe completa che fa quello che vuoi tu, l'altro codice postato era più specifico per wp7 (credevo lavorassi su wp7 confondendomi con altro utente
), ma la sostanza non cambia : (tieni presente che sto modificando il codice da c# a vb)
codice:
Partial Public Class MainWindow
Inherits Window
Public Sub New()
'this.DataContext = new MyViewModel();
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim t As New System.Threading.Thread(AddressOf startThread)
t.Start()
End Sub
Private Sub startThread()
For i As Integer = 0 To 199999
Dispatcher.Invoke(New Action(AddressOf createObjec), System.Windows.Threading.DispatcherPriority.Background)
Next
End Sub
Private i As Integer = 0
Private colore As New SolidColorBrush(Color.FromArgb(255, 0, 0, 0))
Private Sub createObjec()
Dim rect = New Rectangle()
rect.Width = 10
rect.Height = 10
rect.Margin = New Thickness(5, 5 + 5 * i, 0, 0)
rect.Fill = colore
Me.grid.Children.Add(rect)
i += 1
End Sub
End Class
adesso vedo un pò come potresti migliorare le prestazioni per un numero così elevato di elementi.