如何在 Silverlight 中创建月视图控件

发布于 2024-08-13 17:35:48 字数 578 浏览 2 评论 0原文

我需要创建一个像月视图控件这样的 Outlook 来显示约会。 (显示一个月中所有日期的网格,工作日垂直对齐。应显示每天的天数和星期几,并且约会应显示在正确日期内的列表视图中)

我需要一些关于从哪里开始的输入。

假设 ViewModel 看起来像这样:

    public class MonthViewModel
{
    public List<DateTime> DaysInMonth { get; set; }
    public List<Appointment> Appointments { get; set; }
}
    public class Appointment
{
    public string Title { get; set; }
    public DateTime Start { get; set; }
    public string Description { get; set; }

}

我是否需要手动布置日期并安排约会,或者我可以做得更优雅吗?

我已经尝试了几种绑定方法,但均不成功。关于做什么的任何提示?

问候拉尔西

I need to create a outlook like monthview-control for showing appointments. (a grid showing all days in a month, with the weekdays aligned vertically. Day number and dayofweek should be shown for every day, and the appointments should be shown in a listview inside the correct day)

And I need some input on where to start.

Say the ViewModel would look something like this:

    public class MonthViewModel
{
    public List<DateTime> DaysInMonth { get; set; }
    public List<Appointment> Appointments { get; set; }
}
    public class Appointment
{
    public string Title { get; set; }
    public DateTime Start { get; set; }
    public string Description { get; set; }

}

Do I need to manually lay out the days, and place the appointments, or can I do it more elegant?

I've tried several apporoches with binding but all unsuccessful. Any hints on what to do?

Regards Larsi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭了丶谁疼 2024-08-20 17:35:48

几周前我就做了这件事。我所做的是创建两个 silverlight 用户控件,一个用于当天,一个用于月份。

月份控件用日期控件填充名为 MonthRows 的堆栈面板,如下所示:

        ViewStartDate = new DateTime(CurrentDate.Year, CurrentDate.Month, 1);
        ViewEndDate = ViewStartDate.AddMonths(1).AddDays(-1);

        while (ViewStartDate.DayOfWeek != System.DayOfWeek.Sunday)
        {
            ViewStartDate = ViewStartDate.AddDays(-1);
        }
        while (ViewEndDate.DayOfWeek != System.DayOfWeek.Saturday)
        {
            ViewEndDate = ViewEndDate.AddDays(1);
        }

        DateTime tmpDate = ViewStartDate;
        while (tmpDate <= ViewEndDate)
        {
            StackPanel stack = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };

            for (int i = 0; i < 7; i++)
            {
                stack.Children.Add(new ucDay(tmpDate.Year, tmpDate.Month, tmpDate.Day, EventFunc, CurrentDate));
                tmpDate = tmpDate.AddDays(1);
            }
            MonthRows.Children.Add(stack);
        }

ucDay 构造函数接受年、月、日、委托函数指针(以处理单击事件)和当前选定的日期作为参数。

I did this exact thing a few weeks ago. What I did was create two silverlight user controls, one for the day and one for the month.

The month controls fills a stackpanel named MonthRows with day controls like this:

        ViewStartDate = new DateTime(CurrentDate.Year, CurrentDate.Month, 1);
        ViewEndDate = ViewStartDate.AddMonths(1).AddDays(-1);

        while (ViewStartDate.DayOfWeek != System.DayOfWeek.Sunday)
        {
            ViewStartDate = ViewStartDate.AddDays(-1);
        }
        while (ViewEndDate.DayOfWeek != System.DayOfWeek.Saturday)
        {
            ViewEndDate = ViewEndDate.AddDays(1);
        }

        DateTime tmpDate = ViewStartDate;
        while (tmpDate <= ViewEndDate)
        {
            StackPanel stack = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };

            for (int i = 0; i < 7; i++)
            {
                stack.Children.Add(new ucDay(tmpDate.Year, tmpDate.Month, tmpDate.Day, EventFunc, CurrentDate));
                tmpDate = tmpDate.AddDays(1);
            }
            MonthRows.Children.Add(stack);
        }

The ucDay constructor takes in the Year, Month, Day, delegate function pointer (to handle click-events) and the current selected date as parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文