繁体   English   中英

WPF,即使实现属性更改,绑定也不起作用

[英]WPF, Binding not working even with property changed implemented

我遇到绑定到“ StatusBarItem ”的问题。 我还要补充一点,我正在使用“ PropertyChanged.Fody ”来实现我要提出更改的模型。

以下是“ XAML”代码段:

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

基本型号:

[AddINotifyPropertyChangedInterface]
public class IModel {
}

应用模式:

public sealed class ApplicationModel : IModel {

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

    public string Status {
        get;
        set;
    }

}

定位器型号:

public sealed class Locator : IModel {

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

    public ApplicationModel Application => ApplicationModel.Instance;

}

当我想在代码中的任何地方更改“ 状态 ”时,我会这样做:

Locator.Instance.Application.Status = message;

现在我的问题不是' 状态 '不会改变,它会很好地改变。 当应用程序运行时,它将使用ApplicationModel中设置的默认值更新XAML一次。 设置新值后, XAML不会更新为新更改 我觉得我在其他地方使用我的BaseModel都做得很好 ,没有问题。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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