2011-11-20 62 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> 

使用片段或默認的文件這可以製成,而仍不理想比較方便,所以如果有人知道一個很好的修復,請讓我知道。