【发布时间】:2018-11-01 01:55:24
【问题描述】:
我目前在更新标签内容时遇到问题。我在这里缺少什么以更新Current_Plan 属性更新吗?实现见下文:
在我的 xaml 代码中,我有一个名为 LabelProductionPlan 的标签,设置如下:
<Label x:Name="LabelProductionPlan"
Content="{Binding Current_Plan.ProductionPlanName,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"/>
在我的MainWindow.xaml.cs文件中,设置如下:
public partial class MainWindow : Window
{
private FrontEndManager FEM;
public MainWindow()
{
InitializeComponent();
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
FEM = new FrontEndManager
{
Current_Plan = new ProductionPlanModel
{
}
};
LabelProductionPlan.DataContext = FEM;
}}
FrontEndManager 设置了以下Fody feature 以实现 PropertyChanging:
[ImplementPropertyChanging]
public class FrontEndManager
{
public ProductionPlanModel Current_Plan { get; set; }
}
ProductionPlanModel 也与PropertyChanging 一起实现:
[ImplementPropertyChanging]
public class ProductionPlanModel
{
public string ProductionPlanName { get; set; }
}
【问题讨论】:
-
我认为你使用了错误的 Fody 工具 - 你想要 Fody.PropertyChanged
-
我刚刚找到了一个 INotifyPropertyChanging 的实际用例,而不是丑陋的“抛出异常以停止属性设置器”-stackoverflow.com/a/41472332/967885
-
@Peregrine 你是对的!你想提交那个以便我接受你的回答吗?非常感谢你抓住这个!