我正在尝试根据 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/