WPF Can't change time in DatePicker
I'm trying to change Date in the second calendar every time when i change date in first. Problem is, date in second calendar doesn't update days. For example: when i pick 10th of january 2018 on first calendar i should have as first possible day to select 11th of january 2018 on second calendar, and i can select all days except for first. Here's my code:
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateStart = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateEnd = Date1.DisplayDate.AddDays(93);
}
c# wpf datepicker
add a comment |
I'm trying to change Date in the second calendar every time when i change date in first. Problem is, date in second calendar doesn't update days. For example: when i pick 10th of january 2018 on first calendar i should have as first possible day to select 11th of january 2018 on second calendar, and i can select all days except for first. Here's my code:
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateStart = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateEnd = Date1.DisplayDate.AddDays(93);
}
c# wpf datepicker
add a comment |
I'm trying to change Date in the second calendar every time when i change date in first. Problem is, date in second calendar doesn't update days. For example: when i pick 10th of january 2018 on first calendar i should have as first possible day to select 11th of january 2018 on second calendar, and i can select all days except for first. Here's my code:
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateStart = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateEnd = Date1.DisplayDate.AddDays(93);
}
c# wpf datepicker
I'm trying to change Date in the second calendar every time when i change date in first. Problem is, date in second calendar doesn't update days. For example: when i pick 10th of january 2018 on first calendar i should have as first possible day to select 11th of january 2018 on second calendar, and i can select all days except for first. Here's my code:
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateStart = Date1.DisplayDate.AddDays(1);
Date2.DisplayDateEnd = Date1.DisplayDate.AddDays(93);
}
c# wpf datepicker
c# wpf datepicker
edited Jan 2 at 16:31
Stanisław Borkowski
asked Jan 2 at 16:06
Stanisław BorkowskiStanisław Borkowski
124
124
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
My guess is that at the time the event is fired off, the Date1.DisplayDate has not yet updated. You can confirm this in the debugger. Try Date1.SelectedDate instead.
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateStart = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateEnd = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(93) as DateTime?;
}
Note that you may want to change the Date2.SelectedDate as well.
Update: Looks like the SelectedDate is a nullable DateTime. I added a check to see if it is null. If it is a non-null DateTime, I convert it to DateTime to access the AddDays() extension method and then cast it back to nullable DateTime.
Date1.SelectedDate don't have AddDays method :/
– Stanisław Borkowski
Jan 2 at 16:22
Hero <3 ("Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.") Can't upvote ;__;
– Stanisław Borkowski
Jan 2 at 16:36
(had to change Date2.DisplayDate to Date2.SelectedDate in first line for it to work)
– Stanisław Borkowski
Jan 2 at 16:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009508%2fwpf-cant-change-time-in-datepicker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
My guess is that at the time the event is fired off, the Date1.DisplayDate has not yet updated. You can confirm this in the debugger. Try Date1.SelectedDate instead.
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateStart = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateEnd = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(93) as DateTime?;
}
Note that you may want to change the Date2.SelectedDate as well.
Update: Looks like the SelectedDate is a nullable DateTime. I added a check to see if it is null. If it is a non-null DateTime, I convert it to DateTime to access the AddDays() extension method and then cast it back to nullable DateTime.
Date1.SelectedDate don't have AddDays method :/
– Stanisław Borkowski
Jan 2 at 16:22
Hero <3 ("Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.") Can't upvote ;__;
– Stanisław Borkowski
Jan 2 at 16:36
(had to change Date2.DisplayDate to Date2.SelectedDate in first line for it to work)
– Stanisław Borkowski
Jan 2 at 16:38
add a comment |
My guess is that at the time the event is fired off, the Date1.DisplayDate has not yet updated. You can confirm this in the debugger. Try Date1.SelectedDate instead.
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateStart = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateEnd = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(93) as DateTime?;
}
Note that you may want to change the Date2.SelectedDate as well.
Update: Looks like the SelectedDate is a nullable DateTime. I added a check to see if it is null. If it is a non-null DateTime, I convert it to DateTime to access the AddDays() extension method and then cast it back to nullable DateTime.
Date1.SelectedDate don't have AddDays method :/
– Stanisław Borkowski
Jan 2 at 16:22
Hero <3 ("Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.") Can't upvote ;__;
– Stanisław Borkowski
Jan 2 at 16:36
(had to change Date2.DisplayDate to Date2.SelectedDate in first line for it to work)
– Stanisław Borkowski
Jan 2 at 16:38
add a comment |
My guess is that at the time the event is fired off, the Date1.DisplayDate has not yet updated. You can confirm this in the debugger. Try Date1.SelectedDate instead.
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateStart = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateEnd = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(93) as DateTime?;
}
Note that you may want to change the Date2.SelectedDate as well.
Update: Looks like the SelectedDate is a nullable DateTime. I added a check to see if it is null. If it is a non-null DateTime, I convert it to DateTime to access the AddDays() extension method and then cast it back to nullable DateTime.
My guess is that at the time the event is fired off, the Date1.DisplayDate has not yet updated. You can confirm this in the debugger. Try Date1.SelectedDate instead.
private void DateChanged(object sender, SelectionChangedEventArgs e)
{
Date2.DisplayDate = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateStart = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(1) as DateTime?;
Date2.DisplayDateEnd = Date1.SelectedDate is null ? null : ((DateTime)Date1.SelectedDate).AddDays(93) as DateTime?;
}
Note that you may want to change the Date2.SelectedDate as well.
Update: Looks like the SelectedDate is a nullable DateTime. I added a check to see if it is null. If it is a non-null DateTime, I convert it to DateTime to access the AddDays() extension method and then cast it back to nullable DateTime.
edited Jan 2 at 16:26
answered Jan 2 at 16:18
Sudsy1002Sudsy1002
543619
543619
Date1.SelectedDate don't have AddDays method :/
– Stanisław Borkowski
Jan 2 at 16:22
Hero <3 ("Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.") Can't upvote ;__;
– Stanisław Borkowski
Jan 2 at 16:36
(had to change Date2.DisplayDate to Date2.SelectedDate in first line for it to work)
– Stanisław Borkowski
Jan 2 at 16:38
add a comment |
Date1.SelectedDate don't have AddDays method :/
– Stanisław Borkowski
Jan 2 at 16:22
Hero <3 ("Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.") Can't upvote ;__;
– Stanisław Borkowski
Jan 2 at 16:36
(had to change Date2.DisplayDate to Date2.SelectedDate in first line for it to work)
– Stanisław Borkowski
Jan 2 at 16:38
Date1.SelectedDate don't have AddDays method :/
– Stanisław Borkowski
Jan 2 at 16:22
Date1.SelectedDate don't have AddDays method :/
– Stanisław Borkowski
Jan 2 at 16:22
Hero <3 ("Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.") Can't upvote ;__;
– Stanisław Borkowski
Jan 2 at 16:36
Hero <3 ("Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.") Can't upvote ;__;
– Stanisław Borkowski
Jan 2 at 16:36
(had to change Date2.DisplayDate to Date2.SelectedDate in first line for it to work)
– Stanisław Borkowski
Jan 2 at 16:38
(had to change Date2.DisplayDate to Date2.SelectedDate in first line for it to work)
– Stanisław Borkowski
Jan 2 at 16:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009508%2fwpf-cant-change-time-in-datepicker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown