-2

Could somebody please tell me about way to solve problem?

I have simple binding where I want to bind label text to "DateTime" property of one of my classes. The problem is, what this binding correctly works only once when control is loaded, but it doesn't react later, when I change source property value.

I checked, and I am sure what I am changing source property value. I also tried to use different "UpdateSourceTrigger" values, but there were no difference.

What I did wrong here? Could someone please give some ideas? Thank you in advance.

Control

public CheckListTaskControl(ICheckListTask task)
{
       InitializeComponent();
       _task = task;
       dateFromLabel.SetBinding(Label.ContentProperty,
       new Binding()
       {
           Source = _task.TaskDatePeriod,
           Mode = BindingMode.OneWay,
           Path = new PropertyPath("DateFrom"),
           Converter = new DateTimeFormatConverter(),
           UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
           ConverterParameter = _dateFormat
        });
}}

_dateFormat is just string "yyyy-MM-dd HH:mm"

untured
  • 97
  • 7

2 Answers2

0

I suggest you do it in a cleaner way,

You will create Property in ViewModel like this

public DateTime DateTimeProperty { get; set; }

Once you have set in your View something like this

<DatePicker SelectedDate="{Binding DateTimeProperty}"/>

You will be updated on any change

Ohad Cohen
  • 597
  • 4
  • 9
0

Make a class(inherit it from INotifyPropertyChanged) to which your control is bound to implement INotifyPropertyChanged interface, then set your UpdateSourceTrigger to PropertyChanged

NoName
  • 181
  • 8