You don't need these static fields. Just assign the x:Name
property of the ListBox control in the UserControl XAML. Then you can access the ListBox as member of the UserControl class:
<UserControl x:Class="UserControlTest.MyUserControl" ...>
<Grid>
<ListBox x:Name="list" .../>
...
</Grid>
</UserControl>
The above XAML creates a field list
of type ListBox
in class MyUserControl
.
Update: Change the CopyFile
method of your thread class so that it accepts a parameter of type object
and then cast that object to a UserControl reference:
public void CopyFile(object parameter)
{
var userControl = parameter as MyUserControl;
...
}
Then start your thread with the UserControl reference parameter like this:
var cpdfThread = new Thread(new ParameterizedThreadStart(cpdft.CopyFile));
cpdfThread.Start(this); // where this is the UserControl reference
Another alternative would be to just add the UserControl reference as property to your CopyPortDevFileThread
class.
Instead of creating a new Thread for excuting the CopyFile
method you may also use a ThreadPool
thread by e.g. calling ThreadPool.QueueUserWorkItem
.