简体   繁体   English

将DatePicker绑定到日期列表

[英]Bind DatePicker to List of Dates

Probably irrelevant, but I have an Infragistics XamDataChart that has a CategoryXAxis of Dates. 可能无关紧要,但是我有一个Infragistics XamDataChart,它具有Date的CategoryXAxis。 I have managed to bind a date picker to the range of dates available in the chart, but I really need to bind to the specific list of dates plotted on the chart. 我设法将日期选择器绑定到图表中可用的日期范围,但是我确实需要绑定到图表上绘制的特定日期列表。

<DatePicker x:Name="statsDatePicker" DisplayDateStart="{Binding Path=ActualMinimumValue.Date, ElementName=xAxisPath, Mode=OneWay, StringFormat=\{0:d\}}" DisplayDateEnd="{Binding ElementName=xAxisPath, Path=ActualMaximumValue.Date, Mode=OneWay, StringFormat=\{0:d\}}" SelectedDateChanged="DatePicker_SelectedDateChanged" />

I have found that you can provide a list of blackout dates, but how does one take a range of dates I have and turn it into a range of dates I don't? 我发现您可以提供一个停电日期列表,但是如何将某个日期范围内的日期转换为我没有的日期范围呢? Or, is there a way to provide the date picker the dates I have instead of the dates I don't? 或者,是否可以为日期选择器提供我拥有的日期而不是我没有的日期?

Maybe something like this? 也许是这样的吗?

DateTime end = DateTime.MaxValue;
DateTime start = DateTime.MinValue;
List<DateTime> datesIHave= new List<DateTime>();
datesIHave.Add(DateTime.Now);
List<DateTime> allDates = Enumerable.Range(0, 1 + end.Subtract(start).Days).Select(offset => start.AddDays(offset)).ToList();
List<DateTime> blackoutDates = (from a in allDates 
                                where !datesIHave.Contains(a)
                                select a).ToList();

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

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