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
  • Timer是什麼 Timer 是一種用於創建定期粒度行為的機制。 與標準的 .NET System.Threading.Timer 類相似,Orleans 的 Timer 允許在一段時間後執行特定的操作,或者在特定的時間間隔內重覆執行操作。 它在分散式系統中具有重要作用,特別是在處理需要周期性執行的 ...
  • 前言 相信很多做WPF開發的小伙伴都遇到過表格類的需求,雖然現有的Grid控制項也能實現,但是使用起來的體驗感並不好,比如要實現一個Excel中的表格效果,估計你能想到的第一個方法就是套Border控制項,用這種方法你需要控制每個Border的邊框,並且在一堆Bordr中找到Grid.Row,Grid. ...
  • .NET C#程式啟動閃退,目錄導致的問題 這是第2次踩這個坑了,很小的編程細節,容易忽略,所以寫個博客,分享給大家。 1.第一次坑:是windows 系統把程式運行成服務,找不到配置文件,原因是以服務運行它的工作目錄是在C:\Windows\System32 2.本次坑:WPF桌面程式通過註冊表設 ...
  • 在分散式系統中,數據的持久化是至關重要的一環。 Orleans 7 引入了強大的持久化功能,使得在分散式環境下管理數據變得更加輕鬆和可靠。 本文將介紹什麼是 Orleans 7 的持久化,如何設置它以及相應的代碼示例。 什麼是 Orleans 7 的持久化? Orleans 7 的持久化是指將 Or ...
  • 前言 .NET Feature Management 是一個用於管理應用程式功能的庫,它可以幫助開發人員在應用程式中輕鬆地添加、移除和管理功能。使用 Feature Management,開發人員可以根據不同用戶、環境或其他條件來動態地控制應用程式中的功能。這使得開發人員可以更靈活地管理應用程式的功 ...
  • 在 WPF 應用程式中,拖放操作是實現用戶交互的重要組成部分。通過拖放操作,用戶可以輕鬆地將數據從一個位置移動到另一個位置,或者將控制項從一個容器移動到另一個容器。然而,WPF 中預設的拖放操作可能並不是那麼好用。為瞭解決這個問題,我們可以自定義一個 Panel 來實現更簡單的拖拽操作。 自定義 Pa ...
  • 在實際使用中,由於涉及到不同編程語言之間互相調用,導致C++ 中的OpenCV與C#中的OpenCvSharp 圖像數據在不同編程語言之間難以有效傳遞。在本文中我們將結合OpenCvSharp源碼實現原理,探究兩種數據之間的通信方式。 ...
  • 一、前言 這是一篇搭建許可權管理系統的系列文章。 隨著網路的發展,信息安全對應任何企業來說都越發的重要,而本系列文章將和大家一起一步一步搭建一個全新的許可權管理系統。 說明:由於搭建一個全新的項目過於繁瑣,所有作者將挑選核心代碼和核心思路進行分享。 二、技術選擇 三、開始設計 1、自主搭建vue前端和. ...
  • Csharper中的表達式樹 這節課來瞭解一下表示式樹是什麼? 在C#中,表達式樹是一種數據結構,它可以表示一些代碼塊,如Lambda表達式或查詢表達式。表達式樹使你能夠查看和操作數據,就像你可以查看和操作代碼一樣。它們通常用於創建動態查詢和解析表達式。 一、認識表達式樹 為什麼要這樣說?它和委托有 ...
  • 在使用Django等框架來操作MySQL時,實際上底層還是通過Python來操作的,首先需要安裝一個驅動程式,在Python3中,驅動程式有多種選擇,比如有pymysql以及mysqlclient等。使用pip命令安裝mysqlclient失敗應如何解決? 安裝的python版本說明 機器同時安裝了 ...