Hi guys,
I’m making a plug for wpf GUI, the base code came from an unfinished contrib.
It is spreadable now but if I increase the spreadcount to fast in the patch then I get an error :
00:00:15 ERR : Specified Visual is already a child of another Visual or the root of a CompositionTarget.
But if I increase the spreadcount slowly, then no problem. Looks like if UIElementIn.IsChanged is not fast enough at some point.
What do you think ?
Thank you
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms.Integration;
using System.ComponentModel.Composition;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Core.Logging;
namespace VVVV.Packs.UI.Nodes.WPF
{
[PluginInfo(Author = "lecloneur", Name = "Renderer", Category = "WPF", Help = "Renders WPF elements and displays the UI", AutoEvaluate = true, InitialBoxHeight = 120, InitialBoxWidth = 160, InitialComponentMode = TComponentMode.InAWindow, InitialWindowHeight = 300, InitialWindowWidth = 400)](PluginInfo(Author = "lecloneur", Name = "Renderer", Category = "WPF", Help = "Renders WPF elements and displays the UI", AutoEvaluate = true, InitialBoxHeight = 120, InitialBoxWidth = 160, InitialComponentMode = TComponentMode.InAWindow, InitialWindowHeight = 300, InitialWindowWidth = 400))
public class WPFRendererNode : System.Windows.Forms.UserControl, IPluginEvaluate, IUserInputWindow
{
[Input("Background Color", DefaultColor = new[](Input("Background Color", DefaultColor = new[) {0.94, 0.94, 0.94, 1.0}, IsSingle = true, HasAlpha = false, Order = 1)]
public IDiffSpread<RGBAColor> ColorIn;
[Input("Element", Order = 0)](Input("Element", Order = 0))
public IDiffSpread<UIElement> UIElementIn;
[Output("Height", AsInt = true, IsSingle = true, Order = 1)](Output("Height", AsInt = true, IsSingle = true, Order = 1))
public ISpread<int> HeightOut;
[Output("Width", AsInt = true, IsSingle = true, Order = 0)](Output("Width", AsInt = true, IsSingle = true, Order = 0))
public ISpread<int> WidthOut;
[Import()](Import())
public ILogger FLogger;
private readonly ElementHost _container = new ElementHost { Dock = System.Windows.Forms.DockStyle.Fill };
public WPFRendererNode()
{
Controls.Clear();
_container.Child = new Grid();
Controls.Add(_container);
}
public void Evaluate(int SpreadMax)
{
var child = (Grid)_container.Child;
WidthOut[0](0) = _container.Width;
HeightOut[0](0) = _container.Height;
for (var i = 0; i < SpreadMax; i++)
{
if (ColorIn.IsChanged)
_container.BackColor = ColorIn[i](i).Color;
}
if (UIElementIn.IsChanged)
{
child.Children.Clear();
for (var i = 0; i < SpreadMax; i++)
{
child.Children.Add(UIElementIn[i](i));
}
int log = child.Children.Count;
string logg = log.ToString();
string spreadmax = SpreadMax.ToString();
FLogger.Log(LogType.Debug, logg + " : Slider" + " Spread size = "+spreadmax);
}
}
public IntPtr InputWindowHandle
{
get { return _container.Handle; }
}
}
}
https://vvvv.org/sites/default/files/imagecache/large/images/Untitled_1.png