public partial class HTCmds:ResourceDictionary { private ICanvasService mCanvasService;Unity:Dependency Injection
[Dependency]
public ICanvasService CanvasService
{
get { return mCanvasService; }
set { mCanvasService = value; }
}
public HTCmds()
{
CopyCommand = new DelegateCommand<object>(this.Copy, this.CanCopy);
ExitCommand = new DelegateCommand<object>(this.Exit);
}
public DelegateCommand<object> CopyCommand { get; private set; }
public DelegateCommand<object> ExitCommand { get; private set; }
}
資源詞典XAML中:
<ResourceDictionary x:Class="HTCmds"
x:ClassModifier="public"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:commands="clr-namespace:Commands;assembly=UIInfrastructure"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
xmlns:local="clr-namespace:Commands.Commands">
<local:HTCmds x:Key="thisobj"/>
<commands:CommandReference x:Key="CopyCommandReference" Command="{Binding Source={StaticResource thisobj}, Path=CopyCommand}"/>
<commands:CommandReference x:Key="ExitCommandReference" Command="{Binding Source={StaticResource thisobj}, Path=ExitCommand}"/>
</ResourceDictionary>
我已經註冊了ICanvasService,但它不是在這個類中得到注入。資源詞典合併在Windows類的xaml文件中:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Commands/HTCmds.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
ResourceDictionary類是否有特定的內容?
謝謝& Regards, Vishal。
你的問題是什麼?你爲什麼覺得有什麼不對?我們應該在代碼中尋找什麼? – Sjoerd 2010-06-08 14:16:49
我無法獲得ICanvasService。 – Vishal 2010-06-08 15:09:42
你的Unity註冊在哪裏?你在哪裏註冊ICanvasService類型? – Vadim 2010-06-08 15:52:33