Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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# 无法更新XAML文本块文本绑定_C#_Wpf_Xaml - Fatal编程技术网

C# 无法更新XAML文本块文本绑定

C# 无法更新XAML文本块文本绑定,c#,wpf,xaml,C#,Wpf,Xaml,我在XAML中有一个TextBlock,它绑定到一个名为EditSwarming的属性: <TextBlock DockPanel.Dock="Top" Text="{Binding EditsWarning, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{DynamicResource Esri_TextBlockRegular}" HorizontalAl

我在XAML中有一个TextBlock,它绑定到一个名为EditSwarming的属性:

<TextBlock DockPanel.Dock="Top" Text="{Binding EditsWarning, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{DynamicResource Esri_TextBlockRegular}" HorizontalAlignment="Left" FontSize="14" FontWeight="DemiBold" VerticalAlignment="Center" Margin="10,0,10,5" TextWrapping="WrapWithOverflow"/>
EditSwarming属性设置为类的实例,如下所示:

        editsWarning = new OutstandingEditsTextBlock();
        editsWarningMessage = editsWarning.EditsWarningMessage.ToString();
这里是OutstandingEditsTextBlock类,它实现INotifyPropertyChanged

internal class OutstandingEditsTextBlock : INotifyPropertyChanged
{
    private string editsWarning;

    public OutstandingEditsTextBlock()
    {
        if (Project.Current.HasEdits)
        {
            this.editsWarning = "This session/version has outstanding edits.";
        }
        else
        {
            this.editsWarning = string.Empty;
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public string EditsWarningMessage
    {
        get { return this.editsWarning; }

        set
        {
            this.editsWarning = value;
            this.OnPropertyChanged("EditsWarningMessage");
        }
    }

    public void OnPropertyChanged(string propertyName)
    {
        this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}
我注意到我可以让它显示任意一个值,但是,我永远无法让它在同一个调试会话中更新。事实上,看起来公共财产的设定者从未被击中

有人能帮我找出我做错了什么吗


谢谢。

除非您订阅了
OutstandingEditsTextBlock.PropertyChanged
否则
EditsWarning
将如何更新?您的问题缺少提供有用答案所需的选项,但听起来您只是没有正确实现属性。@PeterDuniho-我以为这是订阅了属性:
this.OnPropertyChanged(“EditSwarmingMessage”)
OnPropertyChanged()
的调用不订阅事件。它引发了这一事件。即使它确实订阅了该活动,它也会在错误的地方。您需要指定
EditsWarning
属性的代码来订阅事件,然后在事件处理程序中,每当属性发生更改时,更新
EditsWarning
属性。
internal class OutstandingEditsTextBlock : INotifyPropertyChanged
{
    private string editsWarning;

    public OutstandingEditsTextBlock()
    {
        if (Project.Current.HasEdits)
        {
            this.editsWarning = "This session/version has outstanding edits.";
        }
        else
        {
            this.editsWarning = string.Empty;
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public string EditsWarningMessage
    {
        get { return this.editsWarning; }

        set
        {
            this.editsWarning = value;
            this.OnPropertyChanged("EditsWarningMessage");
        }
    }

    public void OnPropertyChanged(string propertyName)
    {
        this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}