Exemple #1
0
        protected override void LoadThreadSeparatedControl()
        {
            HostVisual = new HostVisual();

            AddLogicalChild(HostVisual);
            AddVisualChild(HostVisual);

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            CommonDispatcher.BeginInvoke(new Action(() =>
            {
                TargetElement = CreateThreadSeparatedControl();

                if (TargetElement == null)
                {
                    return;
                }

                VisualTarget            = new VisualTargetPresentationSource(HostVisual);
                VisualTarget.RootVisual = TargetElement;

                Dispatcher.BeginInvoke(new Action(() => { InvalidateMeasure(); }));
            }));
        }
Exemple #2
0
        protected virtual void LoadThreadSeparatedControl()
        {
            if (SeparateThreadDispatcher != null)
            {
                return;
            }

            AutoResetEvent sync = new AutoResetEvent(false);

            HostVisual = new HostVisual();

            AddLogicalChild(HostVisual);
            AddVisualChild(HostVisual);

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            var thread = new Thread(() =>
            {
                TargetElement = CreateThreadSeparatedControl();

                if (TargetElement == null)
                {
                    return;
                }

                VisualTarget            = new VisualTargetPresentationSource(HostVisual);
                VisualTarget.RootVisual = TargetElement;

                Dispatcher.BeginInvoke(new Action(() => { InvalidateMeasure(); }));

                sync.Set();

                Dispatcher.Run();

                VisualTarget.Dispose();
            })
            {
                IsBackground = true
            };

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            sync.WaitOne();
        }