简体   繁体   中英

WPF, Binding not working even with property changed implemented

I'm running into a problem binding to a ' StatusBarItem '. I'll add that I'm using ' PropertyChanged.Fody ' to implement my models where I want changes to be raised.

Heres the 'XAML' snippet:

<StatusBar Grid.Row="2"
           Background="Transparent"
           Padding="5,0">
    <StatusBarItem Content="{Binding Path=Application.Status, Source={x:Static m:Locator.Instance}}"/>
</StatusBar>

Base Model:

[AddINotifyPropertyChangedInterface]
public class IModel {
}

Application Model:

public sealed class ApplicationModel : IModel {

    static ApplicationModel() {
        Instance = new ApplicationModel() {
            Status = "Ready"
        };
    }
    public static ApplicationModel Instance {
        get;
    }

    public string Status {
        get;
        set;
    }

}

Locater Model:

public sealed class Locator : IModel {

    static Locator() {
        Instance = new Locator();
    }
    public static Locator Instance {
        get;
    }

    public ApplicationModel Application => ApplicationModel.Instance;

}

When I want to change ' Status ' from anywhere in code, I do so like:

Locator.Instance.Application.Status = message;

Now my problem isn't that ' Status ' wont change, it changes just fine. When the application runs, it updates the XAML once with the default value set in ApplicationModel . It's the XAML not updating to the new changes once I set a new value. I feel I've done everything right as I'm using my ' BaseModel ' in other places without problems.

修正:我删除了' PropertyChanged.Fody '包以及' FodyWeavers.xml ',然后在删除了' \\ bin '和' \\ obj '之后重新添加了它们,最后得到了一个干净的解决方案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM