C# PropertyChanged不是从其他程序集中的类激发的

C# PropertyChanged不是从其他程序集中的类激发的,c#,wpf,visual-studio-2017,fody-propertychanged,C#,Wpf,Visual Studio 2017,Fody Propertychanged,我有一个类库,它有一个实现INotifyPropertyChanged的基类BaseViewModel,还有一个派生自TestExternal的类 我使用Fody v4.2.1和PropertyChanged.Fody v2.6.1 在WPF应用程序中,我将该类用作DataContext。更改属性时,它不会反映在应用程序中。但是,如果将该类从类库复制并重命名为TestInternal,则属性更改将反映在应用程序中。TestInternal类派生自类库中相同的BaseViewModel 这个简化示

我有一个类库,它有一个实现INotifyPropertyChanged的基类BaseViewModel,还有一个派生自TestExternal的类

我使用Fody v4.2.1和PropertyChanged.Fody v2.6.1

在WPF应用程序中,我将该类用作DataContext。更改属性时,它不会反映在应用程序中。但是,如果将该类从类库复制并重命名为TestInternal,则属性更改将反映在应用程序中。TestInternal类派生自类库中相同的BaseViewModel

这个简化示例中的类由StringAndObservableCollection组成

ObservableCollection绑定到一个控件,在这两种情况下,添加元素d都会正确地反映在应用程序中。但是将string属性设置为C只反映在TestInternal类中

我需要做什么才能让它工作

BaseViewModel.cs TestExternal.cs TestInternal.cs XAML
为了让Fody注入外部部件,必须指定适当的编织器

指示在项目级别运行的编织器以及使用FodyWeavers.xml文件的顺序。它需要手动添加。其形式如下:

<Weavers>
    <PropertyChanged />
</Weavers>

请参见

您是否有用于外部lib项目的Weavers条目@迈克尔哇,就这么简单。非常感谢。
// This class is in the class library
public class TestExternal : BaseViewModel
{
    public ObservableCollection<string> UserProjects { get; set; }
    public string TestProp { get; set; }
    System.Windows.Application App;

    public TestExternal(System.Windows.Application app)
    {
        this.App = app;
        UserProjects = new ObservableCollection<string>(new List<string>() { "a", "b", "c" });
        TestProp = "A";

        Task.Factory.StartNew(() =>
        {
            Thread.Sleep(5000);
            App.Dispatcher.Invoke((Action)delegate
            {
                TestProp = "C";
                UserProjects.Add("d");
            });
        });
    }
}
// This class is in the WPF app project
public class TestInternal : BaseViewModel
{
    public ObservableCollection<string> UserProjects { get; set; }

    public string TestProp { get; set; }

    System.Windows.Application App;

    public TestInternal(System.Windows.Application app)
    {
        this.App = app;
        UserProjects = new ObservableCollection<string>(new List<string>() { "a", "b", "c" });
        TestProp = "A";

        Task.Factory.StartNew(() =>
        {
            Thread.Sleep(5000);
            App.Dispatcher.Invoke((Action)delegate
            {
                TestProp = "C";
                UserProjects.Add("d");
            });
        });
    }
}
<TextBlock Text="{Binding TestProp}" Style="{StaticResource NaviHeading}" />
<Weavers>
    <PropertyChanged />
</Weavers>