信公眾號:Dotnet9,網站:Dotnet9,問題或建議:請網站留言, 如果對您有所幫助:歡迎贊賞。
快到2020年了,祝大家新年快樂,今年2019最后一更,謝謝大家支持!
閱讀導航
一個系統主界面,放上一個菜單,點擊菜單在客戶區切換不同的展示界面,這是很常規的設計,見下面展示效果圖:
左側一個菜單,點擊菜單,右側切換界面,界面切換動畫使用MD控件的組件實現(自己使用動畫也能實現)。
使用 .NET CORE 3.1 創建名為 “MenuChange” 的WPF模板項目,添加1個Nuget庫:MaterialDesignThemes,版本為最新預覽版3.1.0-ci948。
解決方案主要文件目錄組織結構:
文件【App.xaml】,在 StartupUri 中設置啟動的視圖【MainWindow.xaml】,并在【Application.Resources】節點增加 MaterialDesignThemes庫的樣式文件:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
文件【MainWindow.xaml】,布局代碼、動畫代碼都在此文件中,源碼如下:
<Window x:Class="MenuChange.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Height="600" Width="1024" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None" >
<Grid Background="#FFEEEEEE" MouseDown="Grid_MouseDown">
<StackPanel VerticalAlignment="Top">
<Grid Background="#FF0069C0" Height="10"/>
<Grid Margin="5">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<TextBlock Text="Dotnet9.com" VerticalAlignment="Center" FontSize="20" FontFamily="Champagne & Limousines" Margin="20 0"/>
<Button Width="30" Height="30" Background="{x:Null}" BorderBrush="{x:Null}" Padding="0" Foreground="Gray">
<materialDesign:PackIcon Kind="Wechat"/>
</Button>
<Button Width="30" Height="30" Background="{x:Null}" BorderBrush="{x:Null}" Padding="0" Foreground="Gray">
<materialDesign:PackIcon Kind="Qqchat"/>
</Button>
<Button Width="30" Height="30" Background="{x:Null}" BorderBrush="{x:Null}" Padding="0" Foreground="Gray">
<materialDesign:PackIcon Kind="GithubBox"/>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="10 0">
<Button Width="30" Height="30" Background="{x:Null}" BorderBrush="{x:Null}" Padding="0" Foreground="Gray">
<materialDesign:PackIcon Kind="BellOutline"/>
</Button>
<Button Width="30" Height="30" Background="{x:Null}" BorderBrush="{x:Null}" Padding="0" Foreground="Gray" Margin="0 0 10 0">
<materialDesign:PackIcon Kind="Settings"/>
</Button>
<Button x:Name="ButtonFechar" Width="30" Height="30" Background="{x:Null}" BorderBrush="{x:Null}" Padding="0" Foreground="Gray" Click="ButtonFechar_Click">
<materialDesign:PackIcon Kind="Close"/>
</Button>
</StackPanel>
</Grid>
</StackPanel>
<Grid Margin="250 55 0 0">
<Grid x:Name="GridPrincipal" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Grid Width="250" HorizontalAlignment="Left" Background="#FF222222">
<materialDesign:TransitioningContent x:Name="TrainsitionigContentSlide" OpeningEffect="{materialDesign:TransitionEffect SlideInFromLeft, Duration=0:0:0.2}">
<Grid x:Name="GridCursor" Margin="0 100 0 0" Background="#FF0069C0" Width="10" HorizontalAlignment="Left" Height="60" VerticalAlignment="Top"/>
</materialDesign:TransitioningContent>
<Image Source="https://img.dotnet9.com/logo-head.png" VerticalAlignment="Top"/>
<Image Source="https://img.dotnet9.com/logo-foot.png" VerticalAlignment="Bottom"/>
<ListView x:Name="ListViewMenu" Margin="0 100" Foreground="LightGray" FontFamily="Champagne & Limousines" FontSize="18" SelectionChanged="ListViewMenu_SelectionChanged" SelectedIndex="0">
<ListViewItem Height="60">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Home" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
<TextBlock Text="首頁" FontSize="17" VerticalAlignment="Center" Margin="20 0"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="LanguageCsharp" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
<TextBlock Text="WPF" FontSize="17" VerticalAlignment="Center" Margin="20 0"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="LanguageCsharp" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
<TextBlock Text="Winform" FontSize="17" VerticalAlignment="Center" Margin="20 0"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="LanguageCsharp" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
<TextBlock Text="ASP.NET CORE" FontSize="17" VerticalAlignment="Center" Margin="20 0"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="LanguageCsharp" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
<TextBlock Text="Xamarin.Forms" FontSize="17" VerticalAlignment="Center" Margin="20 0"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="LanguageCpp" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
<TextBlock Text="C++" FontSize="17" VerticalAlignment="Center" Margin="20 0"/>
</StackPanel>
</ListViewItem>
</ListView>
</Grid>
</Grid>
</Window>
簡單說明下:
文件【MainWindow.xaml.cs】,后臺關閉窗體、菜單點擊切換子模塊界面、窗體移動等事件處理:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace MenuChange
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonFechar_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
private void ListViewMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index=ListViewMenu.SelectedIndex;
MoveCursorMenu(index);
switch (index)
{
case 0:
GridPrincipal.Children.Clear();
GridPrincipal.Children.Add(new UserControlMain());
break;
case 1:
GridPrincipal.Children.Clear();
GridPrincipal.Children.Add(new UserControlWPF());
break;
case 2:
GridPrincipal.Children.Clear();
GridPrincipal.Children.Add(new UserControlWinform());
break;
case 3:
GridPrincipal.Children.Clear();
GridPrincipal.Children.Add(new UserControlASPNETCORE());
break;
case 4:
GridPrincipal.Children.Clear();
GridPrincipal.Children.Add(new UserControlXamarinForms());
break;
case 5:
GridPrincipal.Children.Clear();
GridPrincipal.Children.Add(new UserControlCPP());
break;
default:
break;
}
}
private void MoveCursorMenu(int index)
{
TrainsitionigContentSlide.OnApplyTemplate();
GridCursor.Margin=new Thickness(0, (100 + (60 * index)), 0, 0);
}
}
}
方便演示,點擊菜單,切換子用戶控件時時寫死的,見上面的說明,左側菜單及右側切換的子用戶控件需要進行關聯配置,方便擴展,建議使用Prism的模塊化開發。
文件【UserControlMain.xaml】,只展示其中一個子模塊用戶控件吧,其他類似,文末有源碼、可運行Demo供下載參考。
注意: 需要使用MD控件的 TransitioningContent 組件將用戶控件可視區域包裹起來,用于使用MD的移動切換動畫,其中 OpeningEffect 見名思意,即是展示此用戶控件時,動畫如何播放,見下面代碼,SlideInFromLeft 是指示展示時由左向右緩動,相反 SlideInFromRight即是由右向左緩動,其他屬性可查閱MD官網或者Demo研究。
<UserControl x:Class="MenuChange.UserControlMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Height="auto" Width="auto">
<Grid>
<materialDesign:TransitioningContent x:Name="TrainsitionigContentSlide" OpeningEffect="{materialDesign:TransitionEffect SlideInFromLeft, Duration=0:0:0.8}">
<StackPanel Background="#33ff0000">
<TextBox HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="White" Text="https://dotnet9.com"/>
<Image Source="https://img.dotnet9.com/20200124165746.png"/>
</StackPanel>
</materialDesign:TransitioningContent>
</Grid>
</UserControl>
站長方便演示,文中的圖片使用的本站外鏈圖片:
演示Demo下載
除非注明,文章均由 Dotnet9 整理發布,歡迎轉載。
轉載請注明本文地址:https://dotnet9.com/7743.html
時間如流水,只能流去不流回!
、統計圖表ECharts
ECharts,縮寫來自Enterprise Charts,商業級數據圖表,一個純Javascript的圖表庫,可以流暢的運行在PC和移動設備上,兼容當前絕大部分瀏覽器(IE6/7/8/9/10/11,chrome,firefox,Safari等),底層依賴輕量級的Canvas類庫ZRender,提供直觀,生動,可交互,可高度個性化定制的數據可視化圖表。創新的拖拽重計算、數據視圖、值域漫游等特性大大增強了用戶體驗,賦予了用戶對數據進行挖掘、整合的能力。
支持折線圖(區域圖)、柱狀圖(條狀圖)、散點圖(氣泡圖)、K線圖、餅圖(環形圖)、雷達圖(填充雷達圖)、和弦圖、力導向布局圖、地圖、儀表盤、漏斗圖、事件河流圖等12類圖表,同時提供標題,詳情氣泡、圖例、值域、數據區域、時間軸、工具箱等7個可交互組件,支持多圖表、組件的聯動和混搭展現。
主頁:http://echarts.baidu.com/
2、彈窗/層 Layer
layer是一款近年來備受青睞的web彈層組件,她具備全方位的解決方案,致力于服務各水平段的開發人員,您的頁面會輕松地擁有豐富友好的操作體驗。
在與同類組件的比較中,layer總是能輕易獲勝。她盡可能地在以更少的代碼展現更強健的功能,且格外注重性能的提升、易用和實用性。layer兼容了包括IE6在內的所有主流瀏覽器。 她數量可觀的接口,使得您可以自定義太多您需要的風格,每一種彈層模式各具特色,廣受歡迎。
layer遵循LGPL協議,將永久性提供無償服務。歷經數年,截至到2016年09月12日,已運用在20萬余家web平臺,其中包括中國聯通、螞蟻短租、慕課網、phpyun等等知名網站。
主頁:http://layer.layui.com/
3、日期選擇 LayDate
你是時候換一款日期控件了,而layDate非常愿意和您成為工作伙伴。她致力于成為全球最用心的web日期支撐,為國內外所有從事web應用開發的同仁提供力所能及的動力。她基于原生JavaScript精心雕琢,兼容了包括IE6在內的所有主流瀏覽器。她具備優雅的內部代碼,良好的性能體驗,和完善的皮膚體系,并且完全開源,你可以任意獲取開發版源代碼,一掃某些傳統日期控件的封閉與狹隘。layDate本著資源共享的開發者精神和對網頁日歷交互無窮的追求,延續了layui一貫的簡單與易用。她遵循LGPL協議,您可以免費將她用于任何個人項目。
layDate除了包含日期范圍限制、開始日期設定、自定義日期格式、時間戳轉換、當天的前后若干天返回、時分秒選擇、智能響應、自動糾錯、節日識別,快捷鍵操作等常規功能外,還擁有更多趨近完美的解決方案。
主頁:http://laydate.layui.com/
4、表單驗證jQuery Validate
jQuery Validate 插件為表單提供了強大的驗證功能,讓客戶端表單驗證變得更簡單,同時提供了大量的定制選項,滿足應用程序各種需求。該插件捆綁了一套有用的驗證方法,包括 URL 和電子郵件驗證,同時提供了一個用來編寫用戶自定義方法的 API。所有的捆綁方法默認使用英語作為錯誤信息,且已翻譯成其他 37 種語言。
該插件是由 J?rn Zaefferer 編寫和維護的,他是 jQuery 團隊的一名成員,是 jQuery UI 團隊的主要開發人員,是 QUnit 的維護人員。該插件在 2006 年 jQuery 早期的時候就已經開始出現,并一直更新至今。
主頁:https://jqueryvalidation.org/
5、表單向導jquery-steps
jquery-steps是一個聰明的UI組件,它允許您輕松地創建精靈般的接口。這個插件組成部分內容更有條理,有序的頁面視圖。此外,它很簡單,jQuery驗證可以防止步改變或提交。
支持HTML5和交互方法,異步(AJAX)內容加載,容易表單驗證,嵌入式iframe內容,清爽的過渡效果,鍵盤導航,簡單的步驟操作,在一個頁面中的多個向導,輕松導航,狀態持久性。
主頁:http://www.jquery-steps.com/
6、文件上傳Web Uploader
WebUploader是由Baidu WebFE(FEX)團隊開發的一個簡單的以HTML5為主,FLASH為輔的現代文件上傳組件。在現代的瀏覽器里面能充分發揮HTML5的優勢,同時又不摒棄主流IE瀏覽器,沿用原來的FLASH運行時,兼容IE6+,iOS 6+, android 4+。兩套運行時,同樣的調用方式,可供用戶任意選用。 采用大文件分片并發上傳,極大的提高了文件上傳效率。
頭條號這里就是采用了這款圖片上傳插件。
主頁:http://fex.baidu.com/webuploader/
7、圖標庫 阿里巴巴矢量圖標庫
Iconfont.cn是由阿里巴巴UX部門推出的矢量圖標管理網站,也是國內首家推廣Webfont形式圖標的平臺。網站涵蓋了1000多個常用圖標并還在持續更新中,Iconfont平臺為用戶提供在線圖標搜索、圖標分撿下載、在線儲存、矢量格式轉換、個人圖標庫管理及項目圖標管理等基礎功能。同時iconfont.cn平臺作為矢量圖標倡導者,積極在線分享矢量圖標制作經驗、前端應用說明,及應用中常見的一些問題。
主頁:http://www.iconfont.cn/
8、樹形菜單jsTree
jsTree是一個基于jQuery的Tree控件。支持 XML,JSON,Html三種數據源。提供創建,重命名,移動,刪除,拖放節點操作。可以自己自定義創建,刪除,嵌套,重命名,選擇節點的規則。在這些操作上可以添加多種監聽事件。
主頁:https://www.jstree.com/
9、表格Bootstrap table
Bootstrap table是國人開發的一款基于 Bootstrap 的 jQuery 表格插件,通過簡單的設置,就可以擁有強大的單選、多選、排序、分頁,以及編輯、導出、過濾(擴展)等等的功能。目前在github上已經有2600多個Star,可見其受歡迎程度。
支持 Bootstrap 3 和 Bootstrap 2
自適應界面
固定表頭
非常豐富的配置參數
直接通過標簽使用
顯示/隱藏列
顯示/隱藏表頭
通過 AJAX 獲取 JSON 格式的數據
支持排序
格式化表格
支持單選或者多選
強大的分頁功能
支持卡片視圖
支持多語言
支持插件
主頁:http://bootstrap-table.wenzhixin.net.cn/zh-cn/
10、CSS動畫Animation.css
Animation.css是一個迷人的動畫庫,它提供了一堆很酷的,有趣的,跨瀏覽器的動畫,你可以在項目中調用它們。
主頁:https://daneden.github.io/animate.css/
限于篇幅,這次只介紹這10款,說是介紹,其實只是拋磚引玉而已,具體的用法我沒有附上,其實任何一個庫或者控件插件類的,看官方文檔是最佳的使用方式,如果有任何問題,請留言,謝謝
務器控件是服務器可理解的標簽。
經典 ASP 的局限性
下面列出的代碼是從上一章中復制的:
<html>
<body bgcolor="yellow">
<center>
<h2>Hello W3CSchool.cc!</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>
*請認真填寫需求信息,我們會在24小時內與您取得聯系。