Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF数据绑定标签内容_C#_Wpf_Data Binding_Inotifypropertychanged - Fatal编程技术网

C# WPF数据绑定标签内容

C# WPF数据绑定标签内容,c#,wpf,data-binding,inotifypropertychanged,C#,Wpf,Data Binding,Inotifypropertychanged,我正在尝试使用数据绑定创建一个简单的WPF应用程序。 代码看起来不错,但在更新属性时我的视图没有更新。 这是我的XAML: <Window x:Class="Calculator.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ca

我正在尝试使用数据绑定创建一个简单的WPF应用程序。 代码看起来不错,但在更新属性时我的视图没有更新。 这是我的XAML:

<Window x:Class="Calculator.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:calculator="clr-namespace:Calculator"
        Title="MainWindow" Height="350" Width="525"
        Name="MainWindowName">
    <Grid>
        <Label Name="MyLabel" Background="LightGray" FontSize="17pt" HorizontalContentAlignment="Right" Margin="10,10,10,0" VerticalAlignment="Top" Height="40" 
               Content="{Binding Path=CalculatorOutput, UpdateSourceTrigger=PropertyChanged}"/>
    </Grid>
</Window>
这是我的视图模型

namespace Calculator
{
    public class CalculatorViewModel : INotifyPropertyChanged
    {
        private String _calculatorOutput;
        private String CalculatorOutput
        {
            set
            {
                _calculatorOutput = value;
                NotifyPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            var handler = PropertyChanged;
            if (handler != null)
               handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

我很抱歉,我看不到我在这里错过了什么??o、 o

计算器输出没有getter。视图应该如何获得值?该房产也必须是公共的

public String CalculatorOutput
{
    get { return _calculatorOutput; }
    set
    {
        _calculatorOutput = value;
        NotifyPropertyChanged();
    }
}
public String CalculatorOutput
{
    get { return _calculatorOutput; }
    set
    {
        _calculatorOutput = value;
        NotifyPropertyChanged();
    }
}