标签内容不会随着绑定而改变

时间:2018-10-31 16:34:53

标签: c# wpf binding

我目前在更新标签内容方面遇到问题。是否需要在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; }
}

1 个答案:

答案 0 :(得分:-1)

大多数依赖项属性(例如您在Content中绑定的Label)并未使用您正在使用的事件 changing 。您需要使用INotifyPropertyChanged事件,该事件会在值完全更改并且可以使用时提供通知。如前所述,您似乎需要使用Fody.PropertyChanged

相关问题