首页 > 其他分享 >WPF 加载框

WPF 加载框

时间:2023-04-12 12:02:09浏览次数:29  
标签:animationTimer LoadingForm private Visibility WPF PageWindow public 加载

加载框代码:

<UserControl x:Class="WpfApp1.LoadingForm"
             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" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApp1"
             mc:Ignorable="d" 
              Background="Transparent" Height="80" Width="125" BorderThickness="0">
    <Grid>
        <Border CornerRadius="6" Background="#D7D9DB" BorderThickness="1" BorderBrush="#f6f5ec">
        </Border>
        <TextBlock  HorizontalAlignment="Center" Foreground="#4DA4FF" FontSize="16" Canvas.Top="69" Canvas.Left="33" Height="23" VerticalAlignment="Bottom" Width="100" Margin="12,0,13,5"><Run Text="   "/><Run Text=" "/><Run Text="Loading"/></TextBlock>
        <Grid x:Name="LayoutRoot"
              HorizontalAlignment="Center" VerticalAlignment="Center" Margin="32,8,33,12">
            <Grid.RenderTransform>
                <ScaleTransform x:Name="SpinnerScale" 
                                ScaleX="1.0" ScaleY="1.0" />
            </Grid.RenderTransform>
            <Canvas RenderTransformOrigin="0.5,0.5" 
                    HorizontalAlignment="Center" 
                    VerticalAlignment="Center" 
                    Width="60" Height="60" Margin="0,-9,0,9" >
                <Ellipse Width="3" Height="14" 
                         Canvas.Left="20" 
                         Canvas.Top="15" 
                         Stretch="Fill" Fill="#4DA4FF" 
                         Opacity="1.0" RenderTransformOrigin="0.5,0.5">
                    <Ellipse.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="-46.602"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse Width="3" Height="14" 
                         Canvas.Left="17" 
                         Canvas.Top="23" Stretch="Fill" 
                         Fill="#4DA4FF" Opacity="1" RenderTransformOrigin="0.5,0.5">
                    <Ellipse.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="90.301"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse Width="3" Height="14" 
                         Canvas.Left="38" 
                         Canvas.Top="32" Stretch="Fill" 
                         Fill="#4DA4FF" Opacity="1" RenderTransformOrigin="0.5,0.5">
                    <Ellipse.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="-47.324"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse Width="3" Height="14" 
                         Canvas.Left="20" 
                         Canvas.Top="32" Stretch="Fill" 
                         Fill="#4DA4FF" Opacity="1" RenderTransformOrigin="0.5,0.5">
                    <Ellipse.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="46.473"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse Width="3" Height="14" 
                         Canvas.Left="29" 
                         Canvas.Top="35" Stretch="Fill" 
                         Fill="#4DA4FF" Opacity="1" RenderTransformOrigin="0.5,0.5">
                    <Ellipse.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="-0.32"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse Width="3" Height="14" 
                         Canvas.Left="40" 
                         Canvas.Top="23" Stretch="Fill" 
                         Fill="#4DA4FF" Opacity="1" RenderTransformOrigin="0.5,0.5">
                    <Ellipse.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="89.639"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse Width="3" Height="14" 
                         Canvas.Left="29" 
                         Canvas.Top="12" Stretch="Fill" 
                         Fill="#4DA4FF" Opacity="1"/>
                <Ellipse Width="3" Height="14" 
                    Canvas.Left="38" 
                    Canvas.Top="15" Stretch="Fill" 
                    Fill="#4DA4FF" Opacity="1" RenderTransformOrigin="0.5,0.5">
                    <Ellipse.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="-132.963"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Canvas.RenderTransform>
                    <RotateTransform x:Name="SpinnerRotate" 
                                     Angle="0" />
                </Canvas.RenderTransform>
                <Canvas.Triggers>
                    <EventTrigger RoutedEvent="ContentControl.Loaded">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation 
                                    Storyboard.TargetName
                                        ="SpinnerRotate" 
                                     Storyboard.TargetProperty
                                        ="(RotateTransform.Angle)" 
                                     From="0" To="360" 
                                     Duration="0:0:01" 
                                     RepeatBehavior="Forever" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Canvas.Triggers>
            </Canvas>
        </Grid>
    </Grid>
</UserControl>

 后台

namespace WpfApp1
{
    /// <summary>
    /// LoadingForm.xaml 的交互逻辑
    /// </summary>
    public partial class LoadingForm : UserControl
    {
        private readonly DispatcherTimer animationTimer;
        public LoadingForm()
        {
            InitializeComponent();
            animationTimer = new DispatcherTimer(DispatcherPriority.ContextIdle, Dispatcher);
            animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 75); //指定时间间隔
        }
    }
}

使用示例:

前端代码

<Window x:Class="WpfApp1.PageWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CustomSystemWindow.CustomWindow"
        xmlns:ss="clr-namespace:WpfApp1"
        mc:Ignorable="d" Title="PageWindow" WindowState="Maximized"   Height="802" Width="1279" Background="AliceBlue"> 
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="10"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions> 
        <TextBlock Background="Gray"  Grid.Column="0" Text="左侧测试"/>
        <GridSplitter Grid.Row="0" Grid.Column="1" Width="10" HorizontalAlignment="Center" VerticalAlignment="Stretch" Background="Gray"  />

        <Grid Grid.Column="2"  VerticalAlignment="Bottom"  >
            <Grid.RowDefinitions>
                <RowDefinition Height="10"  />
                <RowDefinition Height="200" /> 
            </Grid.RowDefinitions>

            <Button Height="100" Grid.Row="1" Click="Button_Click"  Width="100" Content="右下测试"/>
            <GridSplitter  Grid.Row="0"  Height="10"  HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Background="Red"/>
        </Grid>
        <Grid Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" Width="125" Height="80" >
            <ss:LoadingForm x:Name="LoadingForm" Visibility="Hidden"/>
        </Grid>
    </Grid>
</Window>

后台:

 

namespace WpfApp1
{
    /// <summary>
    /// PageWindow.xaml 的交互逻辑
    /// </summary>
    public partial class PageWindow : Window
    {
        public PageWindow()
        {
            InitializeComponent(); 
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        { 
            LoadingForm.Visibility = Visibility.Visible;  
            var task = Task.Factory.StartNew(
             () =>
             {
                 Thread.Sleep(2000);
                 MessageBox.Show("ssss");
             }, TaskCreationOptions.LongRunning);

            task.ContinueWith((t) => {
                test();
            });
            
        }

        private  void test()
        {
            Action action = () =>
            { 
                LoadingForm.Visibility = Visibility.Hidden;
            };

            this.Dispatcher.Invoke(action); 
        }
    }
}

 结果:

 

标签:animationTimer,LoadingForm,private,Visibility,WPF,PageWindow,public,加载
From: https://www.cnblogs.com/anjingdian/p/17309341.html

相关文章

  • js加载的六种方式
    1.正常模式 <scriptsrc="index.js"></script> 这种情况下JS会阻塞dom渲染,浏览器必须等待index.js加载和执行完成后才能去做其它事情2.async模式<scriptasyncsrc="index.js"></script>async模式下,它的加载是异步的,JS不会阻塞DOM的渲染,async加载是无......
  • Android Kotlin实战之高阶使用泛型扩展协程懒加载详解
    前言:通过前面几篇文章,我们已基本掌握kotlin的基本写法与使用,但是在开发过程中,以及一些开源的API还是会出现大家模式的高阶玩法以及问题,如何避免,接下来讲解针对原来的文章进行一些扩展,解决大家在工作中遇到的问题,如何去解决如果还有人不了解kotlin,可以查看我的基础篇kotlin。Android......
  • 图片防盗链导致图片无法加载解决方法
    我们在博客的时候可能最烦心的就是图片处理了比如我在本地写好博客后把文章发布到博客园,或者CSDN或则和其他平台但是文章中用到的图片需要一个个手动上传,费时费力而且由于图片防盗链的存在,各博客平台上的图片资源又不能直接引用解决方案也很简单,只需要在博客中引入一下代码片......
  • sqlalchemy快速插入数据,scoped_session线程安全,加载类上的装饰器,基本增删改查,django中
    今日内容sqlalchemy快速插入数据sqlalchemy是什么orm框架,跟其他web框架没有必然联系,可以独立使用安装,快速使用,执行原生sql创建表和删除表不能创建数据库不能修改字段(增加,删除)使用orm插入第一步:生成engine对象engine=create_engine("mysql+pymysql://[email protected].......
  • 六、WPF 动态设置菜单,非MVVM模式
     随手建了WPF窗口<Windowx:Class="WpfAppTest.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://sch......
  • 基于elementui的Tree虚线,实线绘制,以及懒加载,如图
     加减号用的是阿里的矢量图标库。自行去下载 路径:https://www.iconfont.cn/home/index?spm=a313x.7781069.1998910419.2 <template><divclass="content-box"><divclass="content-top-lable">系统设置</div><divstyle="padd......
  • Glide 加载圆角图片 CenterCrop
    /***加载圆角图片。并且充满屏幕*/funloadCropImageRadius(iv:ImageView,bkgColor:String?,radius:Int,path:String){valbitMap=ViewTool.createBmp4Rgb(bkgColor)valplaceholderDrawable=BitmapDrawable(iv.resources,bitMap......
  • RecyclerView 上拉加载更多
    //初始化滚动事件valscrollListener=object:RecyclerView.OnScrollListener(){overridefunonScrolled(recyclerView:RecyclerView,dx:Int,dy:Int){super.onScrolled(recyclerView,dx,dy)if(dy>0){......
  • 加载中,三点循环机制
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>加载动画</title></head><style>.dotting{margin:20%auto;width:150px;}.dotting{margi......
  • el-table树形数据与懒加载
    <template><divclass="page"><divclass="page-box"><h3style="margin-top:0">类目/榜单管理</h3><el-inputplaceholder="请输入关键字"v-model="keyWord"style="......