我可以让Kaxaml使用CLR命名空间加载外部程序集,但这很痛苦,因为需要大量映射来定位程序集中的所有不同命名空间,而程序集上的自定义XmlnsDefinition将允许一个人离开只有一个或几个。
在寻找解决方案时,我显然找到了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
命名空间,我必须添加交互式程序集的子命名空间。
如果可以使第一种方法起作用,那将是理想的。
答案 0 :(得分:4)
因此,在输入这个问题时,我偶然发现了一种使用自定义命名空间的方法:你必须让Kaxaml加载程序集至少一次。
这可以使用一些引用引用程序集中的CLR命名空间的虚拟对象来完成。如果解析一旦这个加载器可以被丢弃,当然这需要在每次运行Kaxaml时完成。 e.g。
<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>
使用片段或默认文件,这可以比较方便,但仍然不理想,所以如果有人知道一个好的修复,请告诉我。