.net - VB.Net 中的 WPF 标记扩展不起作用

标签 .net wpf vb.net c#-to-vb.net markup-extensions

我正在尝试根据 this blog post 创建一个 VB.Net 标记扩展但是在 vb.net 中

<Application x:Class="Application"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    ShutdownMode="OnExplicitShutdown">
    <Application.Resources>        
    </Application.Resources>
    <JumpList.JumpList>
        <JumpList ShowRecentCategory="True">
            <JumpTask Title="Save as..." Arguments="-saveas"
                      ApplicationPath="{local:ApplicationFullPath}">
            </JumpTask>
        </JumpList>
    </JumpList.JumpList>
</Application>

但它正在 throw

Error 1 Unknown build error, 'Key cannot be null. Parameter name: key Line 9 Position 62.' C:\Users\jessed.ECREATIVE\My Dropbox\Projects\c2d2\c2d2\Application.xaml 9 62 c2d2

我将示例的 c# 部分转换为

Public Class ApplicationFullPath
    Inherits Markup.MarkupExtension

    Public Overrides Function ProvideValue(ByVal serviceProvider As System.IServiceProvider) As Object
        Return System.Reflection.Assembly.GetExecutingAssembly.Location()
    End Function

End Class

我错过了什么吗?任何帮助将不胜感激

最佳答案

说真的,我绝不会为此使用标记扩展。

不如这样:

public partial class App : Application
{
    public static string ApplicationFullPath
    {
        get { return Assembly.GetExecutingAssembly().Location; }
    }

    ...
<JumpTask ApplicationPath="{x:Static local:App.ApplicationFullPath}"/>

(标记扩展类名称应该以“Extension”结尾,也许这甚至可以解决您的问题(该类将被称为 ApplicationFullPathExtension , XAML 中的调用仍将是 ApplicationFullPath though))

关于.net - VB.Net 中的 WPF 标记扩展不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5670617/

相关文章:

.net - 使 DLL COM 可访问

c# - SslStream 客户端无法完成与 Stunnel 服务器的握手

c# - WPF 在触发器上更改 Grid.ColumnSpan

vb.net - 什么是从vb.net调用php文件的最快方法

vb.net - SelectToken() 路径中有空格

c# - VB "Financial.Pmt"在 C# 中等效?

C# 6 命名空间作为来自强类型命名空间引用的字符串

c# - 配置 IIS 以接收电子邮件

WPF 组合框不响应鼠标

wpf - 命令行为附件参数