3

我有这个:

<Image.Effect>
    <fx:GrayscaleEffect DesaturationFactor="0"/>
</Image.Effect>

和这个:

public class GrayscaleEffect : ShaderEffect{
    private static PixelShader _pixelShader = new PixelShader()
        {
            UriSource = new Uri(@"pack://application:,,,/Effects/GrayscaleEffect.ps")
        };
    /* ... rest of the class ... */
}

当我对它进行MSTest单元测试时IOExceptionApplication.Currentpack://application:,,,/...

Assembly.GetEntryAssembly() returns null. Set the Application.ResourceAssembly property or use the pack://application:,,,/assemblyname;component/ syntax to specify the assembly to load the resource from.

我如何模拟/注入解决它所需的任何东西?

4

2 回答 2

3

好的,明白了,感谢Will

if(Application.ResourceAssembly == null)
    Application.ResourceAssembly = typeof(MainWindow).Assembly;

var window = new MainWindow();
于 2013-08-01T09:33:01.190 回答
3

Tal 的回答对我不起作用,我只是在运行我的测试和 Application.Current 之前在下面调用:

var app = new Application();
于 2015-06-23T13:22:07.853 回答