2011-11-20 55 views
6

我可以让Kaxaml使用CLR名称空间加载外部程序集,但这很痛苦,因为需要大量映射来定位程序集中的所有不同名称空间,而自定义组件上的XmlnsDefinition将允许一个人逃脱只有一个或几个。使用自定义XML名称空间引用Kaxaml中的外部DLL

当寻找一个解决方案,我明显看出this question但似乎只覆盖使用CLR的命名空间作为一切答案似乎为自定义命名空间的工作(“无法设置未知成员......”)。

例子:

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:is="http://schemas.microsoft.com/expression/2010/interactions"> 
<!-- ... --> 
<Button Content="Test"> 
    <i:Interaction.Triggers> 
     <i:EventTrigger EventName="Click"> 
      <is:ChangePropertyAction PropertyName="IsOpen" 
           TargetName="popup" 
           Value="True" /> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 
</Button> 

这是行不通的,但是如果你使用的CLR它:

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:is="clr-namespace:Microsoft.Expression.Interactions;assembly=Microsoft.Expression.Interactions" 
    xmlns:isc="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"> 
<!-- ... --> 
<Button Content="Test"> 
    <i:Interaction.Triggers> 
     <i:EventTrigger EventName="Click"> 
      <isc:ChangePropertyAction PropertyName="IsOpen" 
           TargetName="popup" 
           Value="True" /> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 
</Button> 

is命名空间不在这里使用,我不得不添加的子命名空间交互程序集。

如果可以使第一种方法起作用,那将是理想的。

回答

4

所以,在输入这​​个问题时,我偶然发现了一种使用自定义命名空间的方法:您必须让Kaxaml至少加载一次程序集。

这可以使用一些引用程序集中引用CLR名称空间的虚拟对象来完成。如果一旦这个加载程序可以被丢弃就被解析,当然这需要在每次Kaxaml运行时完成。 例如

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
     xmlns:is="http://schemas.microsoft.com/expression/2010/interactions"> 
    <Page.Resources> 
     <FrameworkElement x:Key="loader" 
       xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
       xmlns:is="clr-namespace:Microsoft.Expression.Interactions;assembly=Microsoft.Expression.Interactions" /> 
    </Page.Resources> 

使用片段或默认的文件这可以制成,而仍不理想比较方便,所以如果有人知道一个很好的修复,请让我知道。