あなたがおっしゃったプロキシのアイデアに似た概念実証を作成することができました。
表示されている問題は、間違ったアセンブリの登録が原因であるためProvideProxyToolboxControlAttribute
、VS統合アセンブリにあるプロキシクラスの属性として使用されるという新しい登録属性を作成しました。ProvideToolboxControlAttribute
実際のコントロールのタイプを使用することを除いて、ほとんど同じです。もちろん、この新しい属性はVSアセンブリにも含まれます。
たとえば、VS以外のアセンブリにツールボックスコントロールがあるとすると、VSアセンブリに次のようMyToolboxControl
な単純なプロキシクラスを作成します。MyToolboxControlProxy
[ProvideProxyToolboxControl("MyToolboxControl", typeof(NonVsAssembly.MyToolboxControl))]
public class ToolboxControlProxy
{
}
そしてもちろん、魔法はで起こりProvideProxyToolboxControlAttribute
ます。これは基本的にこのクラスだけです(簡潔にするためにコメントとパラメーター/エラーチェックは削除されています)。
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
[System.Runtime.InteropServices.ComVisibleAttribute(false)]
public sealed class ProvideProxyToolboxControlAttribute : RegistrationAttribute
{
private const string ToolboxControlsInstallerPath = "ToolboxControlsInstaller";
public ProvideProxyToolboxControlAttribute(string name, Type controlType)
{
this.Name = name;
this.ControlType = controlType;
}
private string Name { get; set; }
private Type ControlType { get; set; }
public override void Register(RegistrationAttribute.RegistrationContext context)
{
using (Key key = context.CreateKey(String.Format(CultureInfo.InvariantCulture, "{0}\\{1}",
ToolboxControlsInstallerPath,
ControlType.AssemblyQualifiedName)))
{
key.SetValue(String.Empty, this.Name);
key.SetValue("Codebase", ControlType.Assembly.Location);
key.SetValue("WPFControls", "1");
}
}
public override void Unregister(RegistrationAttribute.RegistrationContext context)
{
if (context != null)
{
context.RemoveKey(String.Format(CultureInfo.InvariantCulture, "{0}\\{1}",
ToolboxControlsInstallerPath,
ControlType.AssemblyQualifiedName));
}
}
}
うまく機能しているようです。コントロールがツールボックスにあり、適切なレジストリキーが追加されていることを確認しました。
お役に立てれば!