最近一个小项目想用WPF重写一下,需要一个类似Jquery 的blockUI的遮罩层,在后台执行任务的过程中显示Loading...
网上找了一圈,很难找到一个可以现成使用的。最终在基于网上资料的基础上,稍微改造了一下。下面附上代码:
(此方案基于网络搜索获得,感谢提供对应方案的网友们)
1)新建一个BaseWindow.cs类文件
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace xxx.yyy.zzz
{
public class BaseWindow : Window
{
private string layerGridName = "layerGrid";
public BaseWindow()
{
}
public void ShowMask(string message)
{
var form = Application.Current.MainWindow;
//蒙板
Grid layer = new Grid() { Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)) };
TextBlock tx = new TextBlock();
tx.Text = string.IsNullOrEmpty(message) ? "加载中..." : message;
tx.Padding = new Thickness(10, 5, 10, 5);
tx.Background = new SolidColorBrush(Colors.White);
tx.HorizontalAlignment = Hori

最低0.47元/天 解锁文章
815

被折叠的 条评论
为什么被折叠?



