简体   繁体   中英

Textblock binding text

I want to display the string _lunedi in a textbox, the string _lunedi is updated periodically using InitializeBoxes().

I have my class:

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));
        }
    }

whit this method change the lunedi:

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

xaml:

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

The problem is that the text of the textblock is empty. Thank you.

Sounds like the binding is using one time try this instead

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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