wpf MenuItem 預設樣式存檔,方便手頭沒有 vs 時查閱.

来源:https://www.cnblogs.com/8u7tgyjire7890/archive/2022/04/20/16170724.html
-Advertisement-
Play Games

Docker 安裝教程 https://www.studenty.cn/?p=1111 Jenkins 安裝教程 https://www.studenty.cn/?p=1404 新建一個ASP.NET Core API應用程式(需要勾選Docker支持): 在GitHub新建一個項目並上傳代碼 建立 ...


  1         <SolidColorBrush
  2             x:Key="Menu.Static.Background"
  3             Color="#FFF0F0F0" />
  4         <SolidColorBrush
  5             x:Key="Menu.Static.Border"
  6             Color="#FF999999" />
  7         <SolidColorBrush
  8             x:Key="Menu.Static.Foreground"
  9             Color="#FF212121" />
 10         <SolidColorBrush
 11             x:Key="Menu.Static.Separator"
 12             Color="#FFD7D7D7" />
 13         <SolidColorBrush
 14             x:Key="Menu.Disabled.Foreground"
 15             Color="#FF707070" />
 16         <SolidColorBrush
 17             x:Key="MenuItem.Selected.Background"
 18             Color="#3D26A0DA" />
 19         <SolidColorBrush
 20             x:Key="MenuItem.Selected.Border"
 21             Color="#FF26A0DA" />
 22         <SolidColorBrush
 23             x:Key="MenuItem.Highlight.Background"
 24             Color="#3D26A0DA" />
 25         <SolidColorBrush
 26             x:Key="MenuItem.Highlight.Border"
 27             Color="#FF26A0DA" />
 28         <SolidColorBrush
 29             x:Key="MenuItem.Highlight.Disabled.Background"
 30             Color="#0A000000" />
 31         <SolidColorBrush
 32             x:Key="MenuItem.Highlight.Disabled.Border"
 33             Color="#21000000" />
 34         <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
 35         <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry>
 36         <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry>
 37         <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry>
 38         <Geometry x:Key="Checkmark">F1 M 10.0,1.2 L 4.7,9.1 L 4.5,9.1 L 0,5.2 L 1.3,3.5 L 4.3,6.1L 8.3,0 L 10.0,1.2 Z</Geometry>
 39 
 40         <Style
 41             x:Key="MenuScrollButton"
 42             BasedOn="{x:Null}"
 43             TargetType="{x:Type RepeatButton}">
 44             <Setter Property="ClickMode" Value="Hover" />
 45             <Setter Property="Template">
 46                 <Setter.Value>
 47                     <ControlTemplate TargetType="{x:Type RepeatButton}">
 48                         <Border
 49                             x:Name="templateRoot"
 50                             Background="Transparent"
 51                             BorderBrush="Transparent"
 52                             BorderThickness="1"
 53                             SnapsToDevicePixels="true">
 54                             <ContentPresenter
 55                                 Margin="6"
 56                                 HorizontalAlignment="Center"
 57                                 VerticalAlignment="Center" />
 58                         </Border>
 59                     </ControlTemplate>
 60                 </Setter.Value>
 61             </Setter>
 62         </Style>
 63 
 64 
 65         <!-- 彈出的子菜單中 ScrollViewer 的樣式,用於在菜單項較多時,上下滾動顯示所有的菜單項 -->
 66         <Style
 67             x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer,
 68                                          TypeInTargetAssembly={x:Type FrameworkElement}}"
 69             BasedOn="{x:Null}"
 70             TargetType="{x:Type ScrollViewer}">
 71             <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
 72             <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
 73             <Setter Property="Template">
 74                 <Setter.Value>
 75                     <ControlTemplate TargetType="{x:Type ScrollViewer}">
 76                         <Grid SnapsToDevicePixels="true">
 77                             <Grid.ColumnDefinitions>
 78                                 <ColumnDefinition Width="*" />
 79                             </Grid.ColumnDefinitions>
 80 
 81                             <Grid.RowDefinitions>
 82                                 <RowDefinition Height="Auto" />
 83                                 <RowDefinition Height="*" />
 84                                 <RowDefinition Height="Auto" />
 85                             </Grid.RowDefinitions>
 86 
 87                             <!-- 所有的菜單內容 -->
 88                             <Border
 89                                 Grid.Row="1"
 90                                 Grid.Column="0">
 91                                 <ScrollContentPresenter
 92                                     Margin="{TemplateBinding Padding}"
 93                                     CanContentScroll="{TemplateBinding CanContentScroll}" />
 94                             </Border>
 95 
 96                             <!-- 向上滾動按鈕 -->
 97                             <RepeatButton
 98                                 Grid.Row="0"
 99                                 Grid.Column="0"
100                                 Command="{x:Static ScrollBar.LineUpCommand}"
101                                 CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
102                                 Focusable="false"
103                                 Style="{StaticResource MenuScrollButton}">
104                                 <RepeatButton.Visibility>
105                                     <MultiBinding
106                                         Converter="{StaticResource MenuScrollingVisibilityConverter}"
107                                         ConverterParameter="0"
108                                         FallbackValue="Visibility.Collapsed">
109                                         <Binding
110                                             Path="ComputedVerticalScrollBarVisibility"
111                                             RelativeSource="{RelativeSource TemplatedParent}" />
112                                         <Binding
113                                             Path="VerticalOffset"
114                                             RelativeSource="{RelativeSource TemplatedParent}" />
115                                         <Binding
116                                             Path="ExtentHeight"
117                                             RelativeSource="{RelativeSource TemplatedParent}" />
118                                         <Binding
119                                             Path="ViewportHeight"
120                                             RelativeSource="{RelativeSource TemplatedParent}" />
121                                     </MultiBinding>
122                                 </RepeatButton.Visibility>
123                                 <Path
124                                     Data="{StaticResource UpArrow}"
125                                     Fill="{StaticResource Menu.Static.Foreground}" />
126                             </RepeatButton>
127 
128                             <!-- 向下滾動按鈕 -->
129                             <RepeatButton
130                                 Grid.Row="2"
131                                 Grid.Column="0"
132                                 Command="{x:Static ScrollBar.LineDownCommand}"
133                                 CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
134                                 Focusable="false"
135                                 Style="{StaticResource MenuScrollButton}">
136                                 <RepeatButton.Visibility>
137                                     <MultiBinding
138                                         Converter="{StaticResource MenuScrollingVisibilityConverter}"
139                                         ConverterParameter="100"
140                                         FallbackValue="Visibility.Collapsed">
141                                         <Binding
142                                             Path="ComputedVerticalScrollBarVisibility"
143                                             RelativeSource="{RelativeSource TemplatedParent}" />
144                                         <Binding
145                                             Path="VerticalOffset"
146                                             RelativeSource="{RelativeSource TemplatedParent}" />
147                                         <Binding
148                                             Path="ExtentHeight"
149                                             RelativeSource="{RelativeSource TemplatedParent}" />
150                                         <Binding
151                                             Path="ViewportHeight"
152                                             RelativeSource="{RelativeSource TemplatedParent}" />
153                                     </MultiBinding>
154                                 </RepeatButton.Visibility>
155                                 <Path
156                                     Data="{StaticResource DownArrow}"
157                                     Fill="{StaticResource Menu.Static.Foreground}" />
158                             </RepeatButton>
159                         </Grid>
160                     </ControlTemplate>
161                 </Setter.Value>
162             </Setter>
163         </Style>
164 
165         <!-- Role 的文檔詳見 https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.menuitemrole?view=windowsdesktop-6.0 -->
166 
167         <!-- 當 Role= TopLevelItem 時的模版 -->
168         <ControlTemplate
169             x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey,
170                                          TypeInTargetAssembly={x:Type MenuItem}}"
171             TargetType="{x:Type MenuItem}">
172             <Border
173                 x:Name="templateRoot"
174                 Background="{TemplateBinding Background}"
175                 BorderBrush="{TemplateBinding BorderBrush}"
176                 BorderThickness="{TemplateBinding BorderThickness}"
177                 SnapsToDevicePixels="true">
178                 <Grid VerticalAlignment="Center">
179                     <Grid.ColumnDefinitions>
180                         <ColumnDefinition Width="Auto" />
181                         <ColumnDefinition Width="Auto" />
182                     </Grid.ColumnDefinitions>
183                     <ContentPresenter
184                         x:Name="Icon"
185                         Width="16"
186                         Height="16"
187                         Margin="3"
188                         HorizontalAlignment="Center"
189                         VerticalAlignment="Center"
190                         ContentSource="Icon"
191                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
192                     <Path
193                         x:Name="GlyphPanel"
194                         Margin="3"
195                         VerticalAlignment="Center"
196                         Data="{StaticResource Checkmark}"
197                         Fill="{StaticResource Menu.Static.Foreground}"
198                         FlowDirection="LeftToRight"
199                         Visibility="Collapsed" />
200                     <ContentPresenter
201                         Grid.Column="1"
202                         Margin="{TemplateBinding Padding}"
203                         ContentSource="Header"
204                         RecognizesAccessKey="True"
205                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
206                 </Grid>
207             </Border>
208             <ControlTemplate.Triggers>
209                 <Trigger Property="Icon" Value="{x:Null}">
210                     <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
211                 </Trigger>
212                 <Trigger Property="IsChecked" Value="true">
213                     <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" />
214                     <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
215                 </Trigger>
216                 <Trigger Property="IsHighlighted" Value="True">
217                     <Setter TargetName="templateRoot" Property="Background" Value="{StaticResource MenuItem.Highlight.Background}" />
218                     <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Border}" />
219                 </Trigger>
220                 <Trigger Property="IsEnabled" Value="False">
221                     <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{StaticResource Menu.Disabled.Foreground}" />
222                     <Setter TargetName="GlyphPanel" Property="Fill" Value="{StaticResource Menu.Disabled.Foreground}" />
223                 </Trigger>
224                 <MultiTrigger>
225                     <MultiTrigger.Conditions>
226                         <Condition Property="IsHighlighted" Value="True" />
227                         <Condition Property="IsEnabled" Value="False" />
228                     </MultiTrigger.Conditions>
229                     <Setter TargetName="templateRoot" Property="Background" Value="{StaticResource MenuItem.Highlight.Disabled.Background}" />
230                     <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Disabled.Border}" />
231                 </MultiTrigger>
232             </ControlTemplate.Triggers>
233         </ControlTemplate>
234 
235         <!-- 當 Role= TopLevelHeader 時的模版 -->
236         <ControlTemplate
237             x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey,
238                                          TypeInTargetAssembly={x:Type MenuItem}}"
239             TargetType="{x:Type MenuItem}">
240             <Border
241                 x:Name="templateRoot"
242                 Background="{TemplateBinding Background}"
243                 BorderBrush="{TemplateBinding BorderBrush}"
244                 BorderThickness="{TemplateBinding BorderThickness}"
245 	   

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

-Advertisement-
Play Games
更多相關文章
  • 目錄 一.簡介 二.猜你喜歡 零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 基礎 零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 轉場 零基礎 OpenGL (ES) 學習路 ...
  • 前言 最近公司有個PHP項目需要開發維護,之前一直都是跟著巨硬混的,現在要接觸PHP項目。學習一門新語言之前,先搭建好環境吧,鑒於公司項目是基於php 7.1.33 版本的,所以以下我使用的都是基於這個版本的。 下載安裝包 Nginx 下載 http://nginx.org/en/download. ...
  • JDK動態代理中:抽象類不可以被代理 沒有介面不可以被代理 在 Java 8之前,介面可以有常量變數和抽象方法。我們不能在介面中提供方法實現。如果我們要提供抽象方法和非抽象方法(方法與實現)的組合,那麼我們就得使用抽象類。 在 Java 8 介面引入了一些新功能——預設方法和靜態方法。 Java 9 ...
  • 前端除了用js++css+html,還有沒有其它辦法?其實python也可以 1. 安裝與基本流程 Python學習交流Q群:906715085### 安裝 PyWebIO 和其他的第三方庫一樣使用pip install PyWebIO就行,沒有任何難度,此處不做多講。 但是在正式講解一些常見的操作 ...
  • 什麼叫裝箱 & 拆箱? 將int基本類型轉換為Integer包裝類型的過程叫做裝箱,反之叫拆箱。 首先看一段代碼 public static void main(String[] args) { Integer a = 127, b = 127; Integer c = 128, d= 128; S ...
  • 總體來說註解這一塊的內容不是很多,歸納下來:1.註解的定義。2.註解的保存性策略(@Retention)和java內置註解3.註解的反射主要是跟前面的反射機制相結合,反射章節聽完基本都是相同的方法從類-方法--屬性來獲取。 4.註解的作用還是存在在java的反序列化漏洞,當然在java開發中也會有很... ...
  • 在說神經網路之前,我們討論一下神經元(Neurons),它是神經網路的基本單元。神經元先獲得輸入,然後執行某些數學運算 後,再產生一個輸出。比如一個2輸入神經元的例子: 在這個神經元里,輸入總共經歷了3步數學運算,先將輸入乘以權重(weight): 最後經過激活函數(activation funct ...
  • 在今年3月下旬的時候,Java版本已經更新到了18。接下來DD計劃持續做一個系列,主要更新從Java 9開始的各種更新內容,但我不全部都介紹,主要挑一些有意思的內容,以文章和視頻的方式來給大家介紹和學習。為了第一時間獲得內容更新,對文章形式感興趣的小伙伴可以關註我的博客或者公眾號(程式猿DD),對視 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...