繁体   English   中英

文本块绑定文本

[英]Textblock binding text

我想在文本框中显示字符串 _lunedi,使用 InitializeBoxes() 定期更新字符串 _lunedi。

我有我的课:

public event PropertyChangedEventHandler PropertyChanged;
private string _lunedi= "lunedi ";
    public string lunedi
    {
        get { return this._lunedi; }

        set
        {
            if (value != this._lunedi)
            {
                this._lunedi = value;
                NotifyPropertyChanged("lunedi");
            }
        }
    }


    public void NotifyPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

这个方法改变了lunedi:

private void InitializeBoxes()
    {
        lunedi += todayPivot.Day;
    }

xml:

<Border>
    <TextBlock Text="{Binding Path=lunedi, UpdateSourceTrigger=PropertyChanged}"></TextBlock>
</Border>

问题是文本块的文本是空的。 谢谢你。

听起来绑定正在使用一次试试这个

<Border>
<TextBlock Text="{Binding Path=lunedi, Mode=OneWay}"></TextBlock>

暂无
暂无

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

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