gpt4 book ai didi

wpf - 在 Kaxaml 中使用自定义 XML 命名空间引用外部 DLL

转载 作者:行者123 更新时间:2023-12-04 15:26:03 25 4
gpt4 key购买 nike

我可以让 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这里没有使用命名空间,我不得不添加交互程序集的子命名空间。

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

最佳答案

因此,在输入这​​个问题时,我偶然发现了一种使用自定义命名空间的方法:您必须让 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>

使用片段或默认文件这可以相对方便,但仍然不理想,所以如果有人知道一个好的修复请告诉我。

关于wpf - 在 Kaxaml 中使用自定义 XML 命名空间引用外部 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8199226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com