Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Silverlight/WPF日历如何获取可见日期_C#_Wpf_Silverlight_Calendar - Fatal编程技术网

C# Silverlight/WPF日历如何获取可见日期

C# Silverlight/WPF日历如何获取可见日期,c#,wpf,silverlight,calendar,C#,Wpf,Silverlight,Calendar,我想获取日历中的可见日期,例如,对于下图,我想获取2015年6月28日至8月8日的日期 在事件DisplayDateChanged中,我得到的只是 增补日期={01/07/2015 00:00:00}(7月1日) RemovedDate={25/06/2015 00:00:00}(6月25日) 起初,我以为DisplayDateStart和DisplayDateEnd会提供这些信息,但我意识到这些属性不是只读的,而是为其他目的设置的,比如显示的日期范围 那么,有什么解决办法或方法来计算或得到我

我想获取日历中的可见日期,例如,对于下图,我想获取2015年6月28日至8月8日的日期

在事件DisplayDateChanged中,我得到的只是

增补日期={01/07/2015 00:00:00}(7月1日)

RemovedDate={25/06/2015 00:00:00}(6月25日)

起初,我以为DisplayDateStartDisplayDateEnd会提供这些信息,但我意识到这些属性不是只读的,而是为其他目的设置的,比如显示的日期范围


那么,有什么解决办法或方法来计算或得到我想要的结果吗?

我通过一些问题和在日历模板中做一些更改来得到答案

我单击了“编辑其他模板”/“编辑日历日按钮样式”,然后添加了以下内容:

<Setter Property="Tag" Value="{Binding Path=Date}" />

private void myCal_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e)
        {
            var grid = FindVisualChildByName<Grid>(myCal, "MonthView");
            DateTime? dtBegin = null;
            DateTime? dtEnd = null;

            if (grid != null && grid.Children.OfType<System.Windows.Controls.Primitives.CalendarDayButton>().Any())
            {
                foreach (var button in grid.Children.OfType<System.Windows.Controls.Primitives.CalendarDayButton>().Cast<System.Windows.Controls.Primitives.CalendarDayButton>())
                {
                    if (dtBegin == null)
                        dtBegin = Convert.ToDateTime(button.Tag);
                    else
                        dtEnd = Convert.ToDateTime(button.Tag);
                }
            }
        }

        public static T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
            {
                var child = VisualTreeHelper.GetChild(parent, i);
                string controlName = child.GetValue(Control.NameProperty) as string;
                if (controlName == name)
                {
                    return child as T;
                }
                else
                {
                    T result = FindVisualChildByName<T>(child, name);
                    if (result != null)
                        return result;
                }
            }
            return null;
        }

私有无效myCal_DisplayDateChanged(对象发送方,CalendarDateChangedEventArgs e)
{
var grid=FindVisualChildByName(myCal,“MonthView”);
DateTime?dtBegin=null;
DateTime?dtEnd=null;
if(grid!=null&&grid.Children.OfType().Any())
{
foreach(grid.Children.OfType().Cast()中的var按钮)
{
if(dtBegin==null)
dtBegin=Convert.ToDateTime(button.Tag);
其他的
dtEnd=Convert.ToDateTime(button.Tag);
}
}
}
公共静态T FindVisualChildByName(DependencyObject父对象,字符串名称),其中T:DependencyObject
{
for(int i=0;i


我通过一些问题和在日历模板中做一些更改得到了答案

我单击了“编辑其他模板”/“编辑日历日按钮样式”,然后添加了以下内容:

<Setter Property="Tag" Value="{Binding Path=Date}" />

private void myCal_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e)
        {
            var grid = FindVisualChildByName<Grid>(myCal, "MonthView");
            DateTime? dtBegin = null;
            DateTime? dtEnd = null;

            if (grid != null && grid.Children.OfType<System.Windows.Controls.Primitives.CalendarDayButton>().Any())
            {
                foreach (var button in grid.Children.OfType<System.Windows.Controls.Primitives.CalendarDayButton>().Cast<System.Windows.Controls.Primitives.CalendarDayButton>())
                {
                    if (dtBegin == null)
                        dtBegin = Convert.ToDateTime(button.Tag);
                    else
                        dtEnd = Convert.ToDateTime(button.Tag);
                }
            }
        }

        public static T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
            {
                var child = VisualTreeHelper.GetChild(parent, i);
                string controlName = child.GetValue(Control.NameProperty) as string;
                if (controlName == name)
                {
                    return child as T;
                }
                else
                {
                    T result = FindVisualChildByName<T>(child, name);
                    if (result != null)
                        return result;
                }
            }
            return null;
        }

私有无效myCal_DisplayDateChanged(对象发送方,CalendarDateChangedEventArgs e)
{
var grid=FindVisualChildByName(myCal,“MonthView”);
DateTime?dtBegin=null;
DateTime?dtEnd=null;
if(grid!=null&&grid.Children.OfType().Any())
{
foreach(grid.Children.OfType().Cast()中的var按钮)
{
if(dtBegin==null)
dtBegin=Convert.ToDateTime(button.Tag);
其他的
dtEnd=Convert.ToDateTime(button.Tag);
}
}
}
公共静态T FindVisualChildByName(DependencyObject父对象,字符串名称),其中T:DependencyObject
{
for(int i=0;i