我有一个具有两个Canvas控件的应用程序。当应用程序启动时,它会从DLL中加载一个UserControl,它基本上是Canvas和一堆XAML代码。无法在两个不同的画布中使用相同的资源
我希望能够在两个Canvases中显示此控件,但是,当我使用ContentPresenter并将它同时绑定到从DLL加载的控件时,它只在一个画布上显示,而在另一个画布上则不显示“T。我想这是事实,我实际上在两个不同的画布中使用相同的资源,但因为我想避免使用太多的内存(从DLL加载的控件非常重),我没有不想创建相同控件的两个副本。
有没有人有这种情况下更好的方法/解决方案?
这是示出了在两个画布中的一个加载的控制(另一画布使用类似的代码)
<Canvas Width="{Binding MapModel.MapControl.Bounds.Width}" Height="{Binding MapModel.MapControl.Bounds.Height}">
<Canvas.Background>
<VisualBrush>
<VisualBrush.Visual>
<ContentPresenter Content="{Binding MapModel.MapControl}" />
</VisualBrush.Visual>
</VisualBrush>
</Canvas.Background>
</Canvas>
而且从DLL加载由执行XAML:
// Load the map library assembly (Using reflection)
Assembly asm = Assembly.LoadFile(m_fileName);
Type[] tlist = asm.GetTypes();
// Find the class that represents the airport XAML drawing in the assembly, if it finds the airport class then
// set the value to be an instance of that class.
foreach (Type t in tlist)
{
if (t.Name == "Map")
{
MapControl = Activator.CreateInstance(t) as UserControl;
break;
}
}
提前致谢!
你能告诉我们一些代码吗?我只是用图像知道这个问题。 – blindmeis
我已编辑帖子并发布了一些代码,谢谢! –
MapControl是静态的吗?什么类正在加载程序集?你确定你已经创建了2个实例吗? –