3

I have a problem with the Binding nullable property to DatePicker. What i have when run my my App first run but when i set date in range from today to 7 days after it work fine. If i pick date after one week then property set to null. week after

public class Pledge
{
    public int ID { get; set; }
    public string ClientName { get; set; }
    public string Passport { get; set; }
    public string IssuedBy { get; set; }
    [Column(TypeName = "Date")]
    public DateTime? Birthday { get; set; }
    [Column(TypeName = "Date")]
    public DateTime? IssuedDate { get; set; }
    public string Registration { get; set; }
    public string Phone { get; set; }
    public string Model { get; set; }
    public string SerialNumber { get; set; }
    [Column(TypeName = "Date")]
    public DateTime? ReceiptDate { get; set; }
    [Column(TypeName = "Date")]
    public DateTime? IssueDate { get; set; }
    public decimal? Result { get; set; }
    public decimal? MoneyForClient { get; set; }
    public int? Procent { get; set; }
}

XAML:

<StackPanel>
                <TextBlock Text="ФИО:" Margin="4"/>
                <TextBox Text="{Binding Path=ClientName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Номер телефона:" Margin="4"/>
                <xctk:MaskedTextBox Text="{Binding Path=Phone, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Mask="+7 (000) 000-00-00"/>
                <TextBlock Text="Дата рождения:" Margin="4"/>
                <DatePicker Text="{Binding Path=Birthday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Паспорт" Margin="4"/>
                <xctk:MaskedTextBox Text="{Binding Path=Passport, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Mask="0000-000000"/>
                <TextBlock Text="Дата выдачи:" Margin="4"/>
                <DatePicker Text="{Binding Path=IssuedDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Выдан:" Margin="4"/>
                <TextBox Text="{Binding Path=IssuedBy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" AcceptsReturn="True" Height="100"/>
                <TextBlock Text="Прописка:" Margin="4"/>
                <TextBox Text="{Binding Path=Registration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" AcceptsReturn="True" Height="100"/>
                <TextBlock Text="Модель:" Margin="4"/>
                <TextBox Text="{Binding Path=Model, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Серийный номер(IMEI):" Margin="4"/>
                <TextBox Text="{Binding Path=SerialNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Сумма на выдачу:" Margin="4"/>
                <TextBox Text="{Binding Path=MoneyForClient, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Процент:" Margin="4"/>
                <TextBox Text="{Binding Path=Procent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Дата приема:" Margin="4"/>
                <DatePicker Text="{Binding Path=ReceiptDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock Text="Дата выдачи:" Margin="4"/>
                <DatePicker Text="{Binding Path=IssueDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </StackPanel>
2
  • what is the question then? Commented Sep 6, 2017 at 17:03
  • I'm not able to reproduce this problem. Commented Sep 6, 2017 at 17:07

1 Answer 1

6

find the problem. I confused the properties. Instead of the "Text" it was necessary to bind to the "Selected date" in DatePicker. Was:

<DatePicker Text="{Binding Path=MoneyForClient, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

Should be:

<DatePicker SelectedDate="{Binding Path=MoneyForClient, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Sign up to request clarification or add additional context in comments.

3 Comments

weird, TextBox does not have SelectedDate property, but DatePicker does!
TextBox has nothing to do with dates, why would that make sense??? Something doesn't smell right with your answer. Check it.
Corrected inattention

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.