2013-10-25 43 views
0

我不能为了我的生活找出为什么我不能在这本字典中创建我的课程。 Intellisense没有拿起我的WindowCommand<T>课。我检查了程序集名称,它看起来是正确的,在命名空间中也没有错别字。什么让它窒息?为什么我不能在我的资源字典中使用此命令?

WindowCommand.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 

using Ninject; 
using Premier; 
using Premier.View; 

namespace Premier.Command 
{ 
    public class WindowCommand<T> : Command where T : Window 
    { 
     private Func<bool> focus; 
     private int instantiationCount; 

     public bool IsDialog { get; set; } 
     public bool Multiple { get; set; } 

     public WindowCommand() 
     { 
     } 

     public override bool CanExecute(object parameter) 
     { 
      return true; 
     } 

     public override void Execute(object parameter) 
     { 
      var instantiatedOnce = instantiationCount > 0; 

      if (!Multiple && instantiatedOnce) 
      { 
       focus(); 
       return; 
      } 

      instantiationCount++; 

      var w = App.Kernel.Get<T>(); 
      w.Closed += (s, e) => instantiationCount--; 
      focus = w.Focus; 

      if (IsDialog) 
       w.ShowDialog(); 
      else 
       w.Show(); 
     } 
    } 
} 

Windows.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:c="clr-namespace:Premier.Command;assembly=PremierAutoDataExtractor" 
        xmlns:v="clr-namespace:Premier.View;assembly=PremierAutoDataExtractor" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <c:WindowCommand x:Key="ReportsPurchased" x:TypeArguments="v:PurchasedReportsView" /> 
</ResourceDictionary> 

回答

2

x:TypeArguments XAML指令没有在2006年XAML(XML命名空间http://schemas.microsoft.com/winfx/2006/xaml/presentation)的非根XAML元素的支持。如果要在非根XAML元素上使用x:TypeArguments,则应使用XAML2009(xml名称空间http://schemas.microsoft.com/netfx/2009/xaml/presentation)。但是,它只能用于不遵从宽松的XAML。从MSDN页

文字:

在WPF并针对.NET Framework 4的时候,你可以使用XAML 2009 与X特点:TypeArguments但仅用于宽松XAML(XAML 未markup-编译)。用于WPF的标记编译XAML和XAML的BAML格式目前不支持XAML 2009关键字和 功能。如果需要标记编译XAML,则必须在“XAML 2006和WPF Generic XAML 用法”部分中指出的限制下运行 。

因此,恐怕你不能在资源字典中使用你的WindowCommand

链接到MSDN页面获得更多关于x:TypeArguments指令的信息。

相关问题