wpf loading 遮罩层效果(可以用在数据加载时使用)

本文介绍了如何在WPF中创建一个用于数据加载时的loading遮罩层效果。通过分享一个简单的XAML动画实现,展示了基本的遮罩层效果。作者欢迎有更好效果的读者分享交流。
摘要由CSDN通过智能技术生成

一直想做个wpf的loading遮罩效果

闲来无事网上看看别人做的 拔下来一个效果 共享给大家 如果有更好的可以告诉我下

先上个效果图

基本效果就是这样 实现起来也是只有xaml的动画

代码如下

<UserControl x:Class="Test.LoadingMask"
  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" 
  IsHitTestVisible="False"
>
    <UserControl.Resources>
        <!--block style-->
        <Style x:Key="PathStyle" TargetType="Path">
            <Setter Property="Fill" Value="#FF0092FF"></Setter>
            <Setter Property="Stretch" Value="Fill"></Setter>
            <Setter Property="RenderTransformOrigin" Value="0.5,4.3"></Setter>
            <Setter Property="VerticalAlignment" Value="Top"></Setter>
            <Setter Property="Height" Value="10"></Setter>
        </Style>
        <!-- A block in the progress ring (why does this trapezoid have a dozen corners?) -->
        <Geometry x:Key="Block">
            M291.15499,85.897525
			C291.15499,85.897525
			 301.88917,85.87921
			 301.88917,85.87921
			 301.88917,85.87921
			 300.38339,94.355061
			 300.38339,94.355061
			 300.38339,94.355061
			 292.85366,94.355042
			 292.85366,94.355042
			 292.85366,94.355042
			 291.15499,85.897525
			 291.15499,85.897525
			Z
        </Geometry>

        <!-- Animations for the individual blocks of the progress ring -->
        <Storyboard x:Key="ProgressAnimation" RepeatBehavior="Forever">

            <ColorAnimationUsingKeyFrames Duration="00:00:03.6" Storyboard.TargetName="block0" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <LinearColorKeyFrame KeyTime="00:00:00.0" Value="#FF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.2" Value="#EF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.4" Value="#E2000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.6" Value="#D3000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.8" Value="#C6000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.0" Value="#B7000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.2" Value="#AA000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.4" Value="#9B000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.6" Value="#8E000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.8" Value="#7F000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.0" Value="#72000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.2" Value="#63000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.4" Value="#56000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.6" Value="#3D000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.8" Value="#26000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.0" Value="#19000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.2" Value="#0C000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.4" Value="#00000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.6" Value="#FF000000"/>
            </ColorAnimationUsingKeyFrames>

            <ColorAnimationUsingKeyFrames Duration="00:00:03.6" Storyboard.TargetName="block1" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <LinearColorKeyFrame KeyTime="00:00:00.0" Value="#00000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.2" Value="#FF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.4" Value="#EF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.6" Value="#E2000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.8" Value="#D3000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.0" Value="#C6000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.2" Value="#B7000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.4" Value="#AA000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.6" Value="#9B000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.8" Value="#8E000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.0" Value="#7F000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.2" Value="#72000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.4" Value="#63000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.6" Value="#56000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.8" Value="#3D000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.0" Value="#26000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.2" Value="#19000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.4" Value="#0C000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.6" Value="#00000000"/>
            </ColorAnimationUsingKeyFrames>

            <ColorAnimationUsingKeyFrames Duration="00:00:03.6" Storyboard.TargetName="block2" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <LinearColorKeyFrame KeyTime="00:00:00.0" Value="#0C000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.2" Value="#00000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.4" Value="#FF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.6" Value="#EF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.8" Value="#E2000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.0" Value="#D3000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.2" Value="#C6000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.4" Value="#B7000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.6" Value="#AA000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.8" Value="#9B000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.0" Value="#91000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.2" Value="#7F000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.4" Value="#72000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.6" Value="#63000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.8" Value="#56000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.0" Value="#3D000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.2" Value="#26000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.4" Value="#19000000"/>
                <LinearColorKeyFrame KeyTime="00:00:03.6" Value="#0C000000"/>
            </ColorAnimationUsingKeyFrames>

            <ColorAnimationUsingKeyFrames Duration="00:00:03.6" Storyboard.TargetName="block3" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)">
                <LinearColorKeyFrame KeyTime="00:00:00.0" Value="#19000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.2" Value="#0C000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.4" Value="#00000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.6" Value="#FF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:00.8" Value="#EF000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.0" Value="#E2000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.2" Value="#D3000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.4" Value="#C6000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.6" Value="#B7000000"/>
                <LinearColorKeyFrame KeyTime="00:00:01.8" Value="#AA000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.0" Value="#9B000000"/>
                <LinearColorKeyFrame KeyTime="00:00:02.2" Value="#91000000"/>
              
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然可以。以下是一个 DataGridComboBoxColumn 在 WPF使用的示例,并绑定到数据源的代码: 1. 首先,你需要在 XAML 中定义一个 DataGrid 控件,并在其中添加模板列,以包含 DataGridComboBoxColumn: ```xml <DataGrid AutoGenerateColumns="False"> <DataGrid.Columns> <!-- other columns... --> <DataGridTemplateColumn Header="MyComboBox"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox ItemsSource="{Binding ItemsSource}" DisplayMemberPath="DisplayMember" SelectedValuePath="SelectedValue" SelectedValue="{Binding SelectedItem, Mode=TwoWay}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> ``` 2. 接下来,你需要在代码中获取 DataGridComboBoxColumn,并将其绑定到数据源: ```csharp private void SetupDataGrid() { // get the DataGridComboBoxColumn var comboBoxColumn = dataGrid.Columns.First(c => c.Header.Equals("MyComboBox")) as DataGridComboBoxColumn; // setup the ItemsSource binding var binding = new Binding("MyItemsSource") { Source = this }; comboBoxColumn.ItemsSourceBinding = binding; // setup the DisplayMemberPath binding binding = new Binding("MyDisplayMemberPath") { Source = this }; comboBoxColumn.DisplayMemberPathBinding = binding; // setup the SelectedValuePath binding binding = new Binding("MySelectedValuePath") { Source = this }; comboBoxColumn.SelectedValuePathBinding = binding; // setup the SelectedValue binding binding = new Binding("MySelectedValue") { Source = this, Mode = BindingMode.TwoWay }; comboBoxColumn.SelectedValueBinding = binding; } // in your ViewModel or code-behind, define the following properties for each of the bindings: public IEnumerable MyItemsSource { get; set; } public string MyDisplayMemberPath { get; set; } public string MySelectedValuePath { get; set; } public object MySelectedValue { get; set; } ``` 这样就可以在 WPF使用 DataGridComboBoxColumn 并绑定数据源了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值