2011-04-14 95 views
3

我想每this blog post但在vb.netWPF标记扩展在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> 

创建VB.Net标记扩展,但它是扔

错误1未知的构建错误,'密钥不能为空。 参数名称:钥匙行9位置62.' C:\ Users \用户jessed.ECREATIVE \我的收存箱\项目\ 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 

我思念的东西?任何帮助将不胜感激

+0

创建一个标记扩展来返回一个值是...我不知道,只是不这样做。 – 2011-04-14 23:14:15

回答

2

我永远不会使用标记扩展为此,严重。

如何这样的事情,而不是:

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

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

标记扩展类的名称应为“扩展”的方式结束,也许这甚至会解决您的问题(类会被称为ApplicationFullPathExtension,在XAML通话仍然是ApplicationFullPath虽然)

1

我会跟随H.B.建议,但除此之外,您不需要定义上面的“本地”xmlns。你会需要这样的东西:

<Application x:Class="Application" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:MyNamespace" 
    ShutdownMode="OnExplicitShutdown"> 
    <!-- ... existing stuff --> 
</Application> 

哪里了myNameSpace是您的标记扩展中定义的CLR namesapce

如果您下载从博客,你链接到你可以看到完整的示例代码,它是:

<Application x:Class="Jumplist.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:local="clr-namespace:Jumplist" 
      StartupUri="MainWindow.xaml"> 

    <Application.Resources> 

    </Application.Resources> 

    <JumpList.JumpList> 
     <JumpList ShowRecentCategory="True" 
        ShowFrequentCategory="True"> 
      <JumpTask Title="Say Hello!" 
         Description="Display Greeting Message" 
         ApplicationPath="{local:ApplicationFullPath}" 
         Arguments="{x:Static local:ApplicationActions.SayHello}" 
         IconResourcePath="{local:ApplicationFullPath}" 
         IconResourceIndex="0" /> 

     </JumpList> 
    </JumpList.JumpList> 

</Application> 

注意两个本地XMLNS定义,和App在为“跳转列表”的相同的CLR命名空间中定义。

+0

好眼睛,先生(编辑:或女士)。 – 2011-04-14 23:34:28