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
  • 概述:在C#中,++i和i++都是自增運算符,其中++i先增加值再返回,而i++先返回值再增加。應用場景根據需求選擇,首碼適合先增後用,尾碼適合先用後增。詳細示例提供清晰的代碼演示這兩者的操作時機和實際應用。 在C#中,++i 和 i++ 都是自增運算符,但它們在操作上有細微的差異,主要體現在操作的 ...
  • 上次發佈了:Taurus.MVC 性能壓力測試(ap 壓測 和 linux 下wrk 壓測):.NET Core 版本,今天計劃準備壓測一下 .NET 版本,來測試並記錄一下 Taurus.MVC 框架在 .NET 版本的性能,以便後續持續優化改進。 為了方便對比,本文章的電腦環境和測試思路,儘量和... ...
  • .NET WebAPI作為一種構建RESTful服務的強大工具,為開發者提供了便捷的方式來定義、處理HTTP請求並返迴響應。在設計API介面時,正確地接收和解析客戶端發送的數據至關重要。.NET WebAPI提供了一系列特性,如[FromRoute]、[FromQuery]和[FromBody],用 ...
  • 原因:我之所以想做這個項目,是因為在之前查找關於C#/WPF相關資料時,我發現講解圖像濾鏡的資源非常稀缺。此外,我註意到許多現有的開源庫主要基於CPU進行圖像渲染。這種方式在處理大量圖像時,會導致CPU的渲染負擔過重。因此,我將在下文中介紹如何通過GPU渲染來有效實現圖像的各種濾鏡效果。 生成的效果 ...
  • 引言 上一章我們介紹了在xUnit單元測試中用xUnit.DependencyInject來使用依賴註入,上一章我們的Sample.Repository倉儲層有一個批量註入的介面沒有做單元測試,今天用這個示例來演示一下如何用Bogus創建模擬數據 ,和 EFCore 的種子數據生成 Bogus 的優 ...
  • 一、前言 在自己的項目中,涉及到實時心率曲線的繪製,項目上的曲線繪製,一般很難找到能直接用的第三方庫,而且有些還是定製化的功能,所以還是自己繪製比較方便。很多人一聽到自己畫就害怕,感覺很難,今天就分享一個完整的實時心率數據繪製心率曲線圖的例子;之前的博客也分享給DrawingVisual繪製曲線的方 ...
  • 如果你在自定義的 Main 方法中直接使用 App 類並啟動應用程式,但發現 App.xaml 中定義的資源沒有被正確載入,那麼問題可能在於如何正確配置 App.xaml 與你的 App 類的交互。 確保 App.xaml 文件中的 x:Class 屬性正確指向你的 App 類。這樣,當你創建 Ap ...
  • 一:背景 1. 講故事 上個月有個朋友在微信上找到我,說他們的軟體在客戶那邊隔幾天就要崩潰一次,一直都沒有找到原因,讓我幫忙看下怎麼回事,確實工控類的軟體環境複雜難搞,朋友手上有一個崩潰的dump,剛好丟給我來分析一下。 二:WinDbg分析 1. 程式為什麼會崩潰 windbg 有一個厲害之處在於 ...
  • 前言 .NET生態中有許多依賴註入容器。在大多數情況下,微軟提供的內置容器在易用性和性能方面都非常優秀。外加ASP.NET Core預設使用內置容器,使用很方便。 但是筆者在使用中一直有一個頭疼的問題:服務工廠無法提供請求的服務類型相關的信息。這在一般情況下並沒有影響,但是內置容器支持註冊開放泛型服 ...
  • 一、前言 在項目開發過程中,DataGrid是經常使用到的一個數據展示控制項,而通常表格的最後一列是作為操作列存在,比如會有編輯、刪除等功能按鈕。但WPF的原始DataGrid中,預設只支持固定左側列,這跟大家習慣性操作列放最後不符,今天就來介紹一種簡單的方式實現固定右側列。(這裡的實現方式參考的大佬 ...