This project is read-only.

Create UIControl and render it in other theard

Apr 24 at 8:16 AM
Edited Apr 24 at 8:19 AM
I have code in WPF framework:
public class MyObject
    public string Value {set; get;}

public List<MyObject> obj {set;get;}

 private void button_Click(object sender, RoutedEventArgs e)
            Thread thr = new Thread(
                () =>
                    MyUserControl my = new MyUserControl();
                    my.DataContext = obj;

                    Grid grid = new Grid();
                    grid.Measure(new Size(300, 300));
                    grid.Arrange(new Rect(0, 0, 300, 300));

                    grid.UpdateLayout();  // Exception!!!

                    Save(grid); // Save control to png function.
        <ItemsControl ItemsSource="{Binding ElementName=_this, Path=DataContext}">
                    <TextBox Text="{Binding Path=Value}"/>
This code in WPF works fine, but when I copy it to m:ui i has exception (I translate exception text):
System.Windows.Markup.XamlParseException: Exception in object instantiation System.Windows.Controls.TextBox 
InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
How I repair my code to works with m:ui? I need use multitherding to create many users controls.