WPF loading遮罩層 LoadingMask
大家可能很糾結在非同步query資料的時候想在wpf程式中顯示一個loading的遮罩吧
今天就為大家介紹下遮罩的製作
原始碼下載 點選此處
先上張效果圖看看 如果不如您的法眼 可以移步了 或者有更好的效果 可以留言給我
廢話不多說 直接貼程式碼 一個usercontrol
<UserControl x:Class="LoadingMask_Demo.LoadingWait" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" IsVisibleChanged="HandleVisibleChanged"> <UserControl.Background> <SolidColorBrush Color="Black" Opacity="0.2" /> </UserControl.Background> <UserControl.Resources> <SolidColorBrush Color="#FF007BE5" x:Key="CirclesColor" /> <!--<SolidColorBrush Color="Black" x:Key="BackgroundColor" Opacity=".20" />--> </UserControl.Resources> <Viewbox Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid x:Name="LayoutRoot" Background="Transparent" ToolTip="Please wait...." HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14" Foreground="#FFE3953D" FontWeight="Bold" /> <Canvas RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center" Width="120" Height="120" Loaded="HandleLoaded" Unloaded="HandleUnloaded" > <Ellipse x:Name="C0" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="1.0"/> <Ellipse x:Name="C1" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.9"/> <Ellipse x:Name="C2" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.8"/> <Ellipse x:Name="C3" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.7"/> <Ellipse x:Name="C4" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.6"/> <Ellipse x:Name="C5" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.5"/> <Ellipse x:Name="C6" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.4"/> <Ellipse x:Name="C7" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.3"/> <Ellipse x:Name="C8" Width="20" Height="20" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="{StaticResource CirclesColor}" Opacity="0.2"/> <Canvas.RenderTransform> <RotateTransform x:Name="SpinnerRotate" Angle="0" /> </Canvas.RenderTransform> </Canvas> </Grid> </Viewbox> </UserControl> 後臺程式碼: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; namespace LoadingMask_Demo { /// <summary> /// Interaction logic for LoadingWait.xaml /// </summary> public partial class LoadingWait : UserControl { #region Data private readonly DispatcherTimer animationTimer; #endregion #region Constructor public LoadingWait() { InitializeComponent(); animationTimer = new DispatcherTimer( DispatcherPriority.ContextIdle, Dispatcher); animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 90); } #endregion #region Private Methods private void Start() { animationTimer.Tick += HandleAnimationTick; animationTimer.Start(); } private void Stop() { animationTimer.Stop(); animationTimer.Tick -= HandleAnimationTick; } private void HandleAnimationTick(object sender, EventArgs e) { SpinnerRotate.Angle = (SpinnerRotate.Angle + 36) % 360; } private void HandleLoaded(object sender, RoutedEventArgs e) { const double offset = Math.PI; const double step = Math.PI * 2 / 10.0; SetPosition(C0, offset, 0.0, step); SetPosition(C1, offset, 1.0, step); SetPosition(C2, offset, 2.0, step); SetPosition(C3, offset, 3.0, step); SetPosition(C4, offset, 4.0, step); SetPosition(C5, offset, 5.0, step); SetPosition(C6, offset, 6.0, step); SetPosition(C7, offset, 7.0, step); SetPosition(C8, offset, 8.0, step); } private void SetPosition(Ellipse ellipse, double offset, double posOffSet, double step) { ellipse.SetValue(Canvas.LeftProperty, 50.0 + Math.Sin(offset + posOffSet * step) * 50.0); ellipse.SetValue(Canvas.TopProperty, 50 + Math.Cos(offset + posOffSet * step) * 50.0); } private void HandleUnloaded(object sender, RoutedEventArgs e) { Stop(); } private void HandleVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { bool isVisible = (bool)e.NewValue; if (isVisible) Start(); else Stop(); } #endregion } }
呼叫的程式碼也貼出來吧
<Window x:Class="LoadingMask_Demo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:local="clr-namespace:LoadingMask_Demo" > <DockPanel> <StackPanel Orientation="Horizontal" DockPanel.Dock="Top"> <Button Content="show" Width="70" Height="30" Click="ShowButton_Click" /> <Button Content="hide" Width="70" Height="30" Click="HideButton_Click"/> </StackPanel> <Grid Background="#FF484848" DockPanel.Dock="Bottom"> <TextBlock Text="asdfasdfasdf" Foreground="White"/> <local:LoadingWait x:Name="_loading" Visibility="Collapsed"/> </Grid> </DockPanel> </Window> 後臺程式碼 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace LoadingMask_Demo { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void ShowButton_Click(object sender, RoutedEventArgs e) { this._loading.Visibility = Visibility.Visible; } private void HideButton_Click(object sender, RoutedEventArgs e) { this._loading.Visibility = Visibility.Collapsed; } } }
相關推薦
WPF loading遮罩層 LoadingMask
大家可能很糾結在非同步query資料的時候想在wpf程式中顯示一個loading的遮罩吧 今天就為大家介紹下遮罩的製作 原始碼下載 點選此處 先上張效果圖看看 如果不如您的法眼 可以移步了 或者有更好的效果 可以留言給我 廢話不多說 直接貼程式碼 一個usercon
loading 遮罩層
JS程式碼片段 //資料請求方法 var dom = $("#loading").length; if(!dom){ $("body").append("<div id='loading'></div>"); } $("#loa
自己寫的一個按鈕控制元件,點選時在介面出現一個loading遮罩層
Imports System.Collections.Generic Imports System.ComponentModel Imports System.Text Imports System.Web Imports System.Web.UI Imports Syst
C# Winform 實現自定義半透明loading載入遮罩層
在網頁中通過div+css實現半透明效果不難,今天我們看看一種在winfrom中實現的方法: 效果圖如下,正常時: 顯示遮罩層時: 自定義遮罩層控制元件的原始碼如下: 1 using System; 2 using System.Drawing
遮罩層Loading實現
以下是幾個必須的檔案: 1.loading.css: #loading { position: fixed; top: 0; left: 0; width: 100%; height: 1
WPF遮罩層實現
廢話不多說,直接上圖: 上程式碼: 先搞一個基類,方便子窗體複用 public partial class BaseWindow : Window { publ
Winform應用程序實現通用遮罩層
圖片 ted containe completed ini spa mst per 動圖 Winform應用程序實現通用遮罩層 在WEB上,我們在需要進行大數據或復雜邏輯處理時,由於耗時較長,一般我們會在處理過程中的頁面上顯示一個半透明的遮罩層,上面放個圖標或提示:
Winform應用程序實現通用遮罩層二
添加 str img 控件 text 邏輯 mar chang sha 之前先後發表過:《Winform應用程序實現通用遮罩層》、《Winform應用程序實現通用消息窗口》,這兩款遮罩層其實都是基於彈出窗口的,今天為大家分享一個比較簡單但界面相對友好的另一種實現方案,廢話不
JS+CSS簡單實現DIV遮罩層顯示隱藏【轉藏】
button left dtd -m javascrip htm width dex absolute <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/
遮罩層小特效
cti wid bsp z-index log pos absolute 登錄 reat 今天學了一個遮罩層的特效,主要用在網頁裏面註冊頁面和登陸頁面的使用: <style> * { margin: 0px;
隱藏電池欄,遮罩層
idt col interact btn pcl blog num selector select - (BOOL)prefersStatusBarHidden { return YES;//隱藏為YES,顯示為NO } - (void)tapClick:(
實現彈出層,遮罩層
point func relative cit get alpha fun javascrip pla 開發中經常會用到彈出遮罩層的時候,下面是一個簡單的遮罩層彈窗 <style type="text/css"> <
鼠標hover圖片時遮罩層勻速上升顯示內容top、定位
log 功能 float 相對 body idt ive 子元素 hid 1.html <div class="div1"> <div class="div11"> <p >Dolor nunc vule put
前端頁面給指定的div添加遮罩層,並且帶有加載中的小旋轉圖片
left 說了 -s 加載 jquer 其中 ges loading style 話不多說,先上代碼,其實還是比較簡單的 1 $("<div id=‘shade‘ style=‘opacity:0.85;background:white‘></div
遮罩層
fun idt 遮罩 計算 absolut right add borde spl html代碼 <!-- loading 層 --> <div id="loadingDivBack" style="display: none; position:
微信小程序彈出和隱藏遮罩層動畫以及五星評分
weixin cli pan ppm for 數組 HA 分層 ref 參考源碼: http://www.see-source.com/weixinwidget/detail.html?wid=82 https://blog.csdn.net/pcaxb/article
bootstrap模態框hide遮罩層不隱藏解決辦法
bootstrap modal 模態框 hide 問題:在使用ajax提交模態框表單數據後,隱藏模態框並局部刷新,導致遮罩層不消失 原因:模態框隱藏並局部刷新,導致在hide方法沒執行完成時已經局部刷新,沒有隱藏掉遮罩層 解決辦法:方法一:把模態框放在更上層頁面,而不是放在子頁面上 方法二:利
用JavaScript實現CheckBox的全選取消反選,及遮罩層中添加內容
document 當前 CI itl HA posit size classlist ML 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta cha
JS實現遮罩層
ext size UNC document osi white body opacity get /* * 顯示loading遮罩層 */ function loading() { var mask_bg = document.createElement(
web頁在微信中訪問增加遮罩層 右上角彈出在瀏覽器中打開
osi nis scrip div ttr auto nav csdn img https://blog.csdn.net/zgsdzczh/article/details/79744838 web頁在微信中訪問增加遮罩層 右上角彈出在瀏覽器中打開 <sty