WPF数据加载时添加进度条

XML 复制代码
<Window x:Class="YourNamespace.YourWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="YourWindow" Height="350" Width="525">
    <Grid>
        <!-- 其他UI元素 -->

        <!-- 透明的覆盖层,显示在页面上方,包含进度条 -->
        <Grid Visibility="{Binding IsLoading, Converter={StaticResource BoolToVisibilityConverter}}" 
              Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="1">
            <Border Background="Black" Opacity="0.5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <!-- 进度条居中显示 -->
                <ProgressBar x:Name="LoadingProgressBar"
                             IsIndeterminate="True"
                             Height="100" 
                             Width="200" 
                             HorizontalAlignment="Center"
                             VerticalAlignment="Center" 
                             Margin="0, 50, 0, 0" />
            </Border>
        </Grid>

        <!-- 后面的UI元素 -->
        <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left" ZIndex="0">
            <TextBlock Text="Your content goes here..." />
            <!-- 更多元素 -->
        </StackPanel>
        
    </Grid>
</Window>

viewModel代码

cs 复制代码
 // 控制进度条的可见性
 [ObservableProperty]
 private Visibility isLoading = Visibility.Collapsed; // 默认不显示进度条

private void ChangeLoadingStatus(bool isLoading) {

    if (isLoading)
    {
        IsLoading = Visibility.Visible;
    }
    else
    {
        IsLoading = Visibility.Collapsed;
    }

}

[RelayCommand]
private  async void SelectInfo()
{
  string sql ="....."
  ChangeLoadingStatus(true);
  
  var result = await Task.Run(() => dal.db.SqlQueryable<ToolStr50>(sql).ToList());

  ChangeLoadingStatus(false); 

}

页面效果

相关推荐
公众号【林东笔记】获取资料10 小时前
Adobe Photoshop 2024:软件安装包分享和详细安装教程
ui·adobe·photoshop
✎ ﹏梦醒͜ღ҉繁华落℘13 小时前
开发WPF项目时遇到的问题总结
wpf
全栈软件开发20 小时前
PHP域名授权系统网站源码_授权管理工单系统_精美UI_附教程
开发语言·ui·php·php域名授权·授权系统网站源码
hqwest1 天前
C#WPF实战出真汁06--【系统设置】--餐桌类型设置
c#·.net·wpf·布局·分页·命令·viewmodel
Vae_Mars2 天前
WPF中使用InputBindings进行快捷键绑定
wpf
hqwest2 天前
C#WPF实战出真汁05--左侧导航
开发语言·c#·wpf·主界面·窗体设计·视图viewmodel
hqwest2 天前
C#WPF实战出真汁01--项目介绍
开发语言·c#·wpf
wuty0072 天前
WPF 实现支持动态调整高度的文本显示控件
wpf·scrollviewer·extentheight·自动高度控件·动态调整高度
John_ToDebug2 天前
深入解析 Chrome UI 布局配置的设计思想与实现机制
chrome·ui
代码小念3 天前
Pytest+selenium UI自动化测试实战实例(超详细)
selenium·ui·pytest