我是新來的,在編程方面。我正在製作一個只顯示一週的節目。我有幾個星期的約會,我的問題是:有沒有辦法只顯示你當前所在星期的「約會」?WPF日曆周
Q
WPF日曆周
0
A
回答
0
我已經想通了
var googleCal = new GoogleClass();
var ugedag = DateTime.Now.DayOfWeek;
var getMondays = googleCal.GoogleEvents.Where(e => e.StartDate < DateTime.Now.AddDays(6));
var getTuesdays = googleCal.GoogleEvents.Where(e => e.StartDate < DateTime.Now.AddDays(5));
var getWednesday = googleCal.GoogleEvents.Where(e => e.StartDate < DateTime.Now.AddDays(4));
var getThursday = googleCal.GoogleEvents.Where(e => e.StartDate < DateTime.Now.AddDays(3));
var getFriday = googleCal.GoogleEvents.Where(e => e.StartDate < DateTime.Now.AddDays(2));
var getSaturday = googleCal.GoogleEvents.Where(e => e.StartDate < DateTime.Now.AddDays(1));
var getSunday = googleCal.GoogleEvents.Where(e => e.StartDate < DateTime.Now.AddDays(0));
foreach (var googleCalGoogleEvent in googleCal.GoogleEvents)
{
listBox.Items.Add(googleCalGoogleEvent.Title);
}
if (ugedag == DayOfWeek.Monday)
{
foreach (var events in getMondays)
{
NewMethod(events);
}
}
if (ugedag == DayOfWeek.Tuesday)
{
foreach (var events in getTuesdays)
{
NewMethod(events);
}
}
if (ugedag == DayOfWeek.Wednesday)
{
foreach (var events in getWednesday)
{
NewMethod(events);
}
}
if (ugedag == DayOfWeek.Thursday)
{
foreach (var events in getThursday)
{
NewMethod(events);
}
}
if (ugedag == DayOfWeek.Friday)
{
foreach (var events in getFriday)
{
NewMethod(events);
}
}
if (ugedag == DayOfWeek.Saturday)
{
foreach (var events in getSaturday)
{
NewMethod(events);
}
}
if (ugedag == DayOfWeek.Sunday)
{
foreach (var events in getSunday)
{
NewMethod(events);
}
}
}
private void NewMethod(GoogleEvents events)
{
if (events.StartDate.Value.DayOfWeek == DayOfWeek.Monday)
{
Monday.Items.Add($"{events.Title} \n{events.StartDate:dd-MM HH:MM}-{events.EndDate:HH:MM}");
}
if (events.StartDate.Value.DayOfWeek == DayOfWeek.Tuesday)
{
Tuesday.Items.Add($"{events.Title} \n{events.StartDate:dd-MM HH:MM}-{events.EndDate:HH:MM}");
}
if (events.StartDate.Value.DayOfWeek == DayOfWeek.Wednesday)
{
Wednsday.Items.Add($"{events.Title} \n{events.StartDate:dd-MM HH:MM}-{events.EndDate:HH:MM}");
}
if (events.StartDate.Value.DayOfWeek == DayOfWeek.Thursday)
{
Thuesday.Items.Add($"{events.Title} \n{events.StartDate:dd-MM HH:MM}-{events.EndDate:HH:MM}");
}
if (events.StartDate.Value.DayOfWeek == DayOfWeek.Friday)
{
Friday.Items.Add($"{events.Title} \n{events.StartDate:dd-MM HH:MM}-{events.EndDate:HH:MM}");
}
if (events.StartDate.Value.DayOfWeek == DayOfWeek.Saturday)
{
Saturday.Items.Add($"{events.Title} \n{events.StartDate:dd-MM HH:MM}-{events.EndDate:HH:MM}");
}
if (events.StartDate.Value.DayOfWeek == DayOfWeek.Sunday)
{
Sunday.Items.Add($"{events.Title} \n{events.StartDate:dd-MM HH:MM}-{events.EndDate:HH:MM}");
}
}
0
到目前爲止,我有這樣的:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var googleCal = new GoogleClass();
foreach (var googleEvent in googleCal.GoogleEvents)
{
if ((googleEvent.StartDate.Value.DayOfWeek - googleEvent.StartDate.Value.DayOfWeek)
{
listBox.Items.Add(googleEvent.Title + " " + googleEvent.StartDate);
}
}
}
}
public class GoogleEvents
{
public string Title { get; set; }
public DateTime? StartDate { get; set; }
}
class GoogleClass
{
public List<GoogleEvents> GoogleEvents = new List<GoogleEvents>();
static string[] Scopes = { CalendarService.Scope.CalendarReadonly };
static string ApplicationName = "Google Calendar API .NET Quickstart";
public GoogleClass()
{
UserCredential credential;
using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
EventsResource.ListRequest request = service.Events.List("primary");
request.TimeMin = DateTime.Now;
request.ShowDeleted = false;
request.SingleEvents = true;
request.MaxResults = 10;
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
// List events.
Events events = request.Execute();
if (events.Items != null && events.Items.Count > 0)
{
foreach (var eventItem in events.Items)
{
string when = eventItem.Start.DateTime.ToString();
if (String.IsNullOrEmpty(when))
{
when = eventItem.Start.Date;
}
GoogleEvents.Add(new GoogleEvents {Title = eventItem.Summary, StartDate = eventItem.Start.DateTime});
}
}
}
}
+0
我不知道爲什麼它不會允許我的公開課上的代碼 –
+0
但這一天og本週沒有工作,因爲我想它 –
相關問題
- 1. WPF日曆週末着色
- 2. WPF日曆:自定義控件以顯示日曆週數
- 3. 週末日曆
- 4. 周曆減去週日
- 5. 本週Caldroid日曆
- 6. 修改週日歷
- 7. PHP MySQL 7日,周,週一至週五的日曆分頁?
- 8. 週一的日曆開始週數
- 9. 推薦WPF日曆
- 10. WPF日曆可見日期
- 11. 查看日期是否在同一個日曆周或前一個日曆周
- 12. d3.js日曆視圖周
- 13. 從日曆周(SQL Server)的
- 14. 完整的日曆:週末
- 15. 設置日曆下週四
- 16. Ember.js每週日曆導航
- 17. JSF日曆選擇全周
- 18. PHP日曆導航(按周)
- 19. 獲取當前日曆周
- 20. 日曆周視圖Android
- 21. 每週日曆記錄
- 22. PHP的日曆周區間
- 23. 月份週一至週日的日曆顯示日期
- 24. MySQL選擇日曆周內的日期
- 25. 的Javascript月,周,日查看日曆
- 26. Android日曆:獲取下週的日子
- 27. jquery datebox日曆周開始日
- 28. 從週一而不是週日開始反應大日曆?
- 29. Android日曆獲得當前周,前幾周和下週
- 30. Wpf日曆控件定製
請分享你已經嘗試過,並在那裏你卡住了。 StackOverflow是幫助你,而不是爲你做的工作。另外請閱讀[問] – uruloke
我已經在谷歌和YouTube上搜索了任何有關於我的問題後可能有任何問題。 –
更像是以編程的方式分享你所做的事情,而不是使用谷歌搜索或觀看YouTube視頻。 –