WPF日曆控制項

来源:https://www.cnblogs.com/zhangwc/archive/2023/03/30/17272905.html
-Advertisement-
Play Games

在 IIS 上啟用 Websocket 在 Windows Server 2012 或更高版本上啟用對 WebSocket 協議的支持: 備註 使用 IIS Express 時無需執行這些步驟 通過“管理”菜單或“伺服器管理器”中的鏈接使用“添加角色和功能”嚮導。 選擇“基於角色或基於功能的安裝”。 ...


 

從網上找到一個WPF日曆控制項,這個日曆是按天展現的,有0點至23點時間刻度,目前只實現了日曆的增加計劃。

未實現的功能滑鼠單擊選擇(可以選擇多個),選擇後可以進行修改,選擇後可以進行刪除,刷新日曆後重新載入日曆計劃。

日曆控制項包含6個自定義控制項,分別是CalendarTimeslotItem,CalendarLedgerItem,CalendarLedger,CalendarDay,Calendar,CalendarAppointmentItem

CalendarTimeslotItem前臺代碼

 1 <Style TargetType="{x:Type local:CalendarTimeslotItem}">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate TargetType="{x:Type local:CalendarTimeslotItem}">
 5                     <Border Background="{TemplateBinding Background}"
 6                             BorderBrush="#A5BFE1"
 7                             BorderThickness="0,0.5,0,0.5"
 8                             x:Name="bd"
 9                             Height="22">
10                         <Border CornerRadius="4,4,4,4" BorderThickness="1,1,1,1" BorderBrush="#5D8CC9" x:Name="hover" Opacity="0" Background="#10000000">
11                             <!--<TextBlock Text="Click to add appointment" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#A39DD8" />-->
12                         </Border>
13                     </Border>
14                     <ControlTemplate.Triggers>
15                         <Trigger Property="IsMouseOver" Value="True">
16                             <Setter Property="Opacity" Value="1" TargetName="hover" />
17                         </Trigger>
18                     </ControlTemplate.Triggers>
19                 </ControlTemplate>
20             </Setter.Value>
21         </Setter>
22     </Style>
View Code

CalendarLedgerItem前臺代碼

 1 <Style TargetType="{x:Type local:CalendarLedgerItem}">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate TargetType="{x:Type local:CalendarLedgerItem}">
 5                     <Border Background="#E3EFFF"
 6                             BorderBrush="#6593CF"
 7                             BorderThickness="0,0,1,1"
 8                             Height="44" Width="50">
 9                         <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
10                             <TextBlock Text="{TemplateBinding TimeslotA}" Foreground="#9493CF" FontSize="16" Margin="0,3,0,0"/>
11                             <TextBlock Text="{TemplateBinding TimeslotB}" Foreground="#9493CF"  Margin="1.5,0,0,0"/>
12                         </StackPanel>
13                     </Border>
14                 </ControlTemplate>
15             </Setter.Value>
16         </Setter>
17     </Style>
View Code

CalendarLedger前臺代碼

 1     <Style TargetType="{x:Type local:CalendarLedger}">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate TargetType="{x:Type local:CalendarLedger}">
 5                     <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
 6                         <StackPanel>
 7                             <local:CalendarLedgerItem TimeslotA="0" TimeslotB="00" />
 8                             <local:CalendarLedgerItem TimeslotA="1" TimeslotB="00" />
 9                             <local:CalendarLedgerItem TimeslotA="2" TimeslotB="00" />
10                             <local:CalendarLedgerItem TimeslotA="3" TimeslotB="00" />
11                             <local:CalendarLedgerItem TimeslotA="4" TimeslotB="00" />
12                             <local:CalendarLedgerItem TimeslotA="5" TimeslotB="00" />
13                             <local:CalendarLedgerItem TimeslotA="6" TimeslotB="00" />
14                             <local:CalendarLedgerItem TimeslotA="7" TimeslotB="00" />
15                             <local:CalendarLedgerItem TimeslotA="8" TimeslotB="00" />
16                             <local:CalendarLedgerItem TimeslotA="9" TimeslotB="00" />
17                             <local:CalendarLedgerItem TimeslotA="10" TimeslotB="00" />
18                             <local:CalendarLedgerItem TimeslotA="11" TimeslotB="00" />
19                             <local:CalendarLedgerItem TimeslotA="12" TimeslotB="00" />
20                             <local:CalendarLedgerItem TimeslotA="13" TimeslotB="00" />
21                             <local:CalendarLedgerItem TimeslotA="14" TimeslotB="00" />
22                             <local:CalendarLedgerItem TimeslotA="15" TimeslotB="00" />
23                             <local:CalendarLedgerItem TimeslotA="16" TimeslotB="00" />
24                             <local:CalendarLedgerItem TimeslotA="17" TimeslotB="00" />
25                             <local:CalendarLedgerItem TimeslotA="18" TimeslotB="00" />
26                             <local:CalendarLedgerItem TimeslotA="19" TimeslotB="00" />
27                             <local:CalendarLedgerItem TimeslotA="20" TimeslotB="00" />
28                             <local:CalendarLedgerItem TimeslotA="21" TimeslotB="00" />
29                             <local:CalendarLedgerItem TimeslotA="22" TimeslotB="00" />
30                             <local:CalendarLedgerItem TimeslotA="23" TimeslotB="00" />
31                         </StackPanel>
32                     </Border>
33                 </ControlTemplate>
34             </Setter.Value>
35         </Setter>
36     </Style>
View Code

CalendarDay前臺代碼

 1 <Style TargetType="{x:Type local:CalendarDay}">
 2         <Setter Property="ItemsPanel">
 3             <Setter.Value>
 4                 <ItemsPanelTemplate>
 5                     <local:TimeslotPanel />
 6                 </ItemsPanelTemplate>
 7             </Setter.Value>
 8         </Setter>
 9         <Setter Property="Template">
10             <Setter.Value>
11                 <ControlTemplate TargetType="{x:Type local:CalendarDay}">
12                     <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
13                         <Grid>
14                             <StackPanel>
15                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
16                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
17                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
18                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
19                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
20                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
21                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
22                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
23                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
24                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
25                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
26                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
27                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
28                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
29                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
30                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
31                                 <local:CalendarTimeslotItem Background="White" />
32                                 <local:CalendarTimeslotItem Background="White" />
33                                 <local:CalendarTimeslotItem Background="White" />
34                                 <local:CalendarTimeslotItem Background="White" />
35                                 <local:CalendarTimeslotItem Background="White" />
36                                 <local:CalendarTimeslotItem Background="White" />
37                                 <local:CalendarTimeslotItem Background="White" />
38                                 <local:CalendarTimeslotItem Background="White" />
39                                 <local:CalendarTimeslotItem Background="White" />
40                                 <local:CalendarTimeslotItem Background="White" />
41                                 <local:CalendarTimeslotItem Background="White" />
42                                 <local:CalendarTimeslotItem Background="White" />
43                                 <local:CalendarTimeslotItem Background="White" />
44                                 <local:CalendarTimeslotItem Background="White" />
45                                 <local:CalendarTimeslotItem Background="White" />
46                                 <local:CalendarTimeslotItem Background="White" />
47                                 <local:CalendarTimeslotItem Background="White" />
48                                 <local:CalendarTimeslotItem Background="White" />
49                                 <local:CalendarTimeslotItem Background="White" />
50                                 <local:CalendarTimeslotItem Background="White" />
51                                 <local:CalendarTimeslotItem Background="White" />
52                                 <local:CalendarTimeslotItem Background="White" />
53                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
54                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
55                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
56                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
57                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
58                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
59                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
60                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
61                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
62                                 <local:CalendarTimeslotItem Background="#E6EDF7" />
63                             </StackPanel>
64                             <ItemsPresenter />
65                         </Grid>
66                     </Border>
67                 </ControlTemplate>
68             </Setter.Value>
69         </Setter>
70     </Style>
View Code

Calendar前臺代碼

 1 <Style TargetType="{x:Type local:Calendar}">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate TargetType="{x:Type local:Calendar}">
 5                     <Border Background="#E3EFFF" BorderBrush="#6593CF" BorderThickness="2,2,2,2">
 6                         <Grid>
 7                             <Grid.ColumnDefinitions>
 8                                 <ColumnDefinition Width="50" />
 9                                 <ColumnDefinition Width="*" />
10                             </Grid.ColumnDefinitions>
11                             <Grid.RowDefinitions>
12                                 <RowDefinition Height="38" />
13                                 <RowDefinition Height="22" />
14                                 <RowDefinition Height="*" />
15                             </Grid.RowDefinitions>
16 
17                             <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,0,0,0">
18                                 <Button Height="25" Command="{x:Static local:Calendar.PreviousDay}" Background="{x:Null}" BorderBrush="{x:Null}">
19                                     <Image Source="/Images/Previous.png" />
20                                 </Button>
21                                 <Button Height="25" Command="{x:Static local:Calendar.NextDay}" Background="{x:Null}" BorderBrush="{x:Null}">
22                                     <Image Source="/Images/Next.png" />
23                                 </Button>
24                             </StackPanel>
25                             <Border BorderBrush="#6593CF" BorderThickness="0,0,1,1" Grid.Column="0" Grid.Row="1" />
26                             <Border BorderBrush="#6593CF" BorderThickness="0,1,0,1" Background="#30000000" Grid.Column="1" Grid.Row="1">
27                                 <TextBlock Text="{TemplateBinding CurrentDate}" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="dayHeader" />
28                             </Border>
29                             <ScrollViewer Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
30                                 <Grid>
31                                     <Grid.ColumnDefinitions>
32                                         <ColumnDefinition Width="50" />
33                                         <ColumnDefinition Width="*" />
34                                     </Grid.ColumnDefinitions>
35 
36                                     <local:CalendarLedger Grid.Column="0" />
37                                     <local:CalendarDay Grid.Column="1" x:Name="day" />
38                                 </Grid>
39                             </ScrollViewer>
40                         </Grid>
41                     </Border>
42                 </ControlTemplate>
43             </Setter.Value>
44         </Setter>
45     </Style>
View Code

CalendarAppointmentItem前臺代碼

 1 <Style TargetType="{x:Type local:CalendarAppointmentItem}">
 2         <Setter Property="AppointmentItem" Value="{Binding AppointmentItem}"/>
 3         <Setter Property="StartTime" Value="{Binding StartTime}"/>
 4         <Setter Property="EndTime" Value="{Binding EndTime}"/>
 5         <Setter Property="Template">
 6             <Setter.Value>
 7                 <ControlTemplate TargetType="{x:Type local:CalendarAppointmentItem}">
 8                     <Border CornerRadius="1,1,1,1" BorderThickness="1,1,1,1" BorderBrush="#5D8CC9" Background="#F1F5E3" Margin="1,1,1,1" Padding="3,1,0,1">
 9                         <ContentPresenter ToolTip="{Binding}" />
10                     </Border>
11                 </ControlTemplate>
12             </Setter.Value>
13         </Setter>
14     </Style>
View Code

日曆控制項是用WPF自定義控制項做的,裡面有些複雜,實在不知道如何實現上述功能,有人願意研究可以看一下,提供源碼。

鏈接:https://pan.baidu.com/s/15G9scu-l_uelMbTUyagilg
提取碼:6666

 

--------------------------------------------------
只有對寫程式充滿熱情,才能寫出好的程式!

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Java重寫toString的意義 一.toString()方法 toString()方法在Object類里定義的,其返回值類型為String類型,返回類名和它的引用地址. 在進行String類與其他類型的連接操作時,自動調用toString()方法,demo如下: Date time = new ...
  • 一、問題引入 單鏈表的實現【01】:Student-Management-System 只體現了項目功能實現,未對代碼部分做出說明。 故新增隨筆進行補充說明代碼部分。 重構代碼,迭代版本:Student Mangement System(Version 2.0) 二、解決過程 基於單鏈表實現就離不開 ...
  • 在java,c#類的成員修飾符包括,公有、私有、程式集可用的、受保護的。 對於python來說,只有兩個成員修飾符:公有成員,私有成員 成員修飾符是來修飾誰呢?當然是修飾成員了。那麼python類的成員包括什麼呢? python成員: 欄位,方法,屬性 每個類成員的修飾符有兩種: 公有成員:內部外部 ...
  • 前言 RocketMQ是阿裡巴巴旗下一款開源的MQ框架,經歷過雙十一考驗、Java編程語言實現,有非常好完整生態系統。RocketMQ作為一款純java、分散式、隊列模型的開源消息中間件,支持事務消息、順序消息、批量消息、定時消息、消息回溯等 本篇文章第一部分屬於一些核心概念和工作流程的講解;第二部 ...
  • 針對大量log日誌快速定位錯誤地方 動態查看日誌 tail -f catalina.ou 從頭打開日誌文件 cat catalina.ou 可以使用 >nanjiangtest.txt 輸出某個新日誌去查看 [root@yesky logs]# cat -n catalina.out |grep 7 ...
  • 近段時間忙於各種項目和對【易排平臺】的優化,沒顧得上分享APS相關的小技巧,回頭看看小公眾號的關註人數早已達1500+,在此爭取時間寫一下這段時間在項目上及平臺優化過程中遇到的一些小技巧,以感謝諸位的關註。過去數月的解決的問題中,涉及最多的是規劃模型中,實現各種時間維度的功能,目前在平臺上也稍有成果 ...
  • 呆了2個大屏行業的公司,對大屏幕有一些瞭解,所以整理下所瞭解的觸摸屏相關概念。方便自己以及進入這個行業的小伙伴們,能有個系統、快速的認知。 觸摸屏詳細的知識點,網上其實都有。整理資料過程中,我也瞭解了更多的觸摸屏知識,像聲波屏、光學屏之類的之前就沒接觸。下麵分不同的模塊,給大家介紹 交互觸摸屏類型 ...
  • C#-垃圾回收機制(GC) 什麼是GC 官網中有這麼一句話: The garbage collector is a common language runtime component that controls the allocation and release of managed memory ...
一周排行
    -Advertisement-
    Play Games
  • 1、預覽地址:http://139.155.137.144:9012 2、qq群:801913255 一、前言 隨著網路的發展,企業對於信息系統數據的保密工作愈發重視,不同身份、角色對於數據的訪問許可權都應該大相徑庭。 列如 1、不同登錄人員對一個數據列表的可見度是不一樣的,如數據列、數據行、數據按鈕 ...
  • 前言 上一篇文章寫瞭如何使用RabbitMQ做個簡單的發送郵件項目,然後評論也是比較多,也是準備去學習一下如何確保RabbitMQ的消息可靠性,但是由於時間原因,先來說說設計模式中的簡單工廠模式吧! 在瞭解簡單工廠模式之前,我們要知道C#是一款面向對象的高級程式語言。它有3大特性,封裝、繼承、多態。 ...
  • Nodify學習 一:介紹與使用 - 可樂_加冰 - 博客園 (cnblogs.com) Nodify學習 二:添加節點 - 可樂_加冰 - 博客園 (cnblogs.com) 介紹 Nodify是一個WPF基於節點的編輯器控制項,其中包含一系列節點、連接和連接器組件,旨在簡化構建基於節點的工具的過程 ...
  • 創建一個webapi項目做測試使用。 創建新控制器,搭建一個基礎框架,包括獲取當天日期、wiki的請求地址等 創建一個Http請求幫助類以及方法,用於獲取指定URL的信息 使用http請求訪問指定url,先運行一下,看看返回的內容。內容如圖右邊所示,實際上是一個Json數據。我們主要解析 大事記 部 ...
  • 最近在不少自媒體上看到有關.NET與C#的資訊與評價,感覺大家對.NET與C#還是不太瞭解,尤其是對2016年6月發佈的跨平臺.NET Core 1.0,更是知之甚少。在考慮一番之後,還是決定寫點東西總結一下,也回顧一下.NET的發展歷史。 首先,你沒看錯,.NET是跨平臺的,可以在Windows、 ...
  • Nodify學習 一:介紹與使用 - 可樂_加冰 - 博客園 (cnblogs.com) Nodify學習 二:添加節點 - 可樂_加冰 - 博客園 (cnblogs.com) 添加節點(nodes) 通過上一篇我們已經創建好了編輯器實例現在我們為編輯器添加一個節點 添加model和viewmode ...
  • 前言 資料庫併發,數據審計和軟刪除一直是數據持久化方面的經典問題。早些時候,這些工作需要手寫複雜的SQL或者通過存儲過程和觸發器實現。手寫複雜SQL對軟體可維護性構成了相當大的挑戰,隨著SQL字數的變多,用到的嵌套和複雜語法增加,可讀性和可維護性的難度是幾何級暴漲。因此如何在實現功能的同時控制這些S ...
  • 類型檢查和轉換:當你需要檢查對象是否為特定類型,並且希望在同一時間內將其轉換為那個類型時,模式匹配提供了一種更簡潔的方式來完成這一任務,避免了使用傳統的as和is操作符後還需要進行額外的null檢查。 複雜條件邏輯:在處理複雜的條件邏輯時,特別是涉及到多個條件和類型的情況下,使用模式匹配可以使代碼更 ...
  • 在日常開發中,我們經常需要和文件打交道,特別是桌面開發,有時候就會需要載入大批量的文件,而且可能還會存在部分文件缺失的情況,那麼如何才能快速的判斷文件是否存在呢?如果處理不當的,且文件數量比較多的時候,可能會造成卡頓等情況,進而影響程式的使用體驗。今天就以一個簡單的小例子,簡述兩種不同的判斷文件是否... ...
  • 前言 資料庫併發,數據審計和軟刪除一直是數據持久化方面的經典問題。早些時候,這些工作需要手寫複雜的SQL或者通過存儲過程和觸發器實現。手寫複雜SQL對軟體可維護性構成了相當大的挑戰,隨著SQL字數的變多,用到的嵌套和複雜語法增加,可讀性和可維護性的難度是幾何級暴漲。因此如何在實現功能的同時控制這些S ...