WPF 新手引导
参考了https://www.cnblogs.com/ZXdeveloper/p/8391864.html,自己随便实现了一个,记录下,比较丑

<Window x:Class="UserGuide.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UserGuide"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="35,44,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<Button x:Name="o1" Content="Button" HorizontalAlignment="Left" Margin="274,340,0,0" VerticalAlignment="Top" Width="75"/>
<TextBox x:Name="o2" HorizontalAlignment="Left" Height="23" Margin="387,154,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Label x:Name="o3" Content="Label" HorizontalAlignment="Left" Margin="301,63,0,0" VerticalAlignment="Top"/> <Canvas x:Name="can" Background="#33121212" Visibility="Collapsed" />
</Grid>
</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 UserGuide
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{ List<GuideModel> _elList;
int _currentIndex = ;
PathGeometry borGeometry = new PathGeometry(); public MainWindow()
{
InitializeComponent();
_elList = new List<GuideModel>()
{
new GuideModel(){ EL=o1,FBtnDesc="下一步",FDesc="这是Button"},
new GuideModel(){ EL=o2,FBtnDesc="下一步",FDesc="这是Textbox"},
new GuideModel(){ EL=o3,FBtnDesc="关闭",FDesc="这是label"}
}; } private void Button_Click(object sender, RoutedEventArgs e)
{
_currentIndex = ;
can.Visibility = Visibility.Visible;
StartGuide();
} private void CreateGuide(GuideModel el)
{ can.Visibility = Visibility.Visible;
can.Children.Clear();
Point point = el.EL.TransformToAncestor(Window.GetWindow(el.EL)).Transform(new Point(, ));//获取控件坐标点 //设置canvas的clip
RectangleGeometry rg = new RectangleGeometry();
rg.Rect = new Rect(, , this.ActualWidth, this.ActualHeight);
borGeometry = Geometry.Combine(borGeometry, rg, GeometryCombineMode.Union, null);
can.Clip = borGeometry; RectangleGeometry rg1 = new RectangleGeometry();
rg1.Rect = new Rect(point.X - , point.Y - , el.EL.ActualWidth + , el.EL.ActualHeight + );
borGeometry = Geometry.Combine(borGeometry, rg1, GeometryCombineMode.Exclude, null); can.Clip = borGeometry; UC uc = new UC();
uc.SetLbl(el.FDesc);//设置引导描述
uc.SetBtn(el.FBtnDesc);//设置按钮描述
uc.NextFlag += StartGuide;//按钮委托
//设置引导控件位置
uc.SetValue(LeftProperty, point.X + el.EL.ActualWidth);
uc.SetValue(TopProperty, point.Y + el.EL.ActualHeight);
can.Children.Add(uc); _currentIndex++;
} private void StartGuide()
{
if (_currentIndex >= _elList.Count)
{
can.Visibility = Visibility.Collapsed;
return;
} CreateGuide(_elList[_currentIndex]);
}
} public class GuideModel
{
public FrameworkElement EL { get; set; }
public string FDesc { get; set; }
public string FBtnDesc { get; set; }
} }
添加一个引导控件
<UserControl x:Class="UserGuide.UC"
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:UserGuide"
mc:Ignorable="d"
Height="200" Width="300">
<Grid Background="Red">
<Label x:Name="lbl" Content="Label" HorizontalAlignment="Left" Margin="65,61,0,0" VerticalAlignment="Top"/>
<Button x:Name="btn" Content="Button" HorizontalAlignment="Left" Margin="172,128,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click" /> </Grid>
</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; namespace UserGuide
{
/// <summary>
/// UC.xaml 的交互逻辑
/// </summary>
public partial class UC : UserControl
{ public delegate void NextFlagHandle();
public NextFlagHandle NextFlag; public UC()
{
InitializeComponent();
} private void Button_Click(object sender, RoutedEventArgs e)
{
NextFlag();
} public void SetLbl(string lblValue)
{
lbl.Content = lblValue;
}
public void SetBtn(string btnValue)
{
btn.Content = btnValue;
}
}
}
自己写着玩玩的,用到项目中肯定需要美化的,基本功能实现了。
WPF 新手引导的更多相关文章
- WPF|快速添加新手引导功能(支持MVVM)
阅读导航 前言 案例一 案例二 案例三(本文介绍的方式) 如何使用? 控件如何开发的? 总结 1. 前言 案例一 站长分享过 眾尋 大佬的一篇 WPF 简易新手引导 一文,新手引导的效果挺不错的,如下 ...
- WPF 简易新手引导
这两天不忙,所以,做了一个简易的新手引导小Demo.因为,不是项目上应用,所以,做的很粗糙,也就是给需要的人,一个思路而已. 新手引导功能的话,就是告诉用户,页面上操作的顺序,第一步要做什么,第二步要 ...
- 在WPF中使用依赖注入的方式创建视图
在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...
- MVVM框架从WPF移植到UWP遇到的问题和解决方法
MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...
- MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息
MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- MVVM设计模式和WPF中的实现(四)事件绑定
MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(二)数据绑定
MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
随机推荐
- ES6系列_12之map数据结构
1.map数据结构出现的原因? JavaScript 的对象(Object),本质上是键值对的集合(Hash 结构),但是传统上只能用字符串当作键.这给它的使用带来了很大的限制.为了能实现将对象作为键 ...
- ES6系列_1之开发环境搭建
前言: 1.es6的简单介绍: ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,已经在2015年6月正式发布了.它的目标,是使得 JavaScript 语言 ...
- HTTP 返回码 400
400(错误请求)服务器不理解请求的语法 404表示页面不存在 返回500表示内部服务出错, 返回301表示资源永久性跳转 HTTP 500 – 内部服务器错误 HTTP 500.100 – 内部服务 ...
- Python Geoip 获取IP地址经度、纬度
简介: 除了一些免费的 API 接口,例如 http://ipinfo.io/223.155.166.172 可以得到一些信息外,还可以通过 python-geoip 库来解决这个问题. shell ...
- 关于SQLServer2000中触发器的使用——多行数据提交
关于触发器的使用,有很多争议.触发器的好处不言而喻是增强了数据的校验能力,能够有效地实现复杂的业务逻辑.在一定程度上走的比约束和check走的更远.关于触发器的坏处,最典型的就是触发器的使用会导致系统 ...
- hive中修改序列化格式分隔符
标签: hadoophivealtertable 2014-11-19 10:45 4219人阅读 评论(0) 收藏 举报 分类: hadoop(6) 版权声明:本文为博主原创文章,未经博主允许不 ...
- 通过Jenkins自动构建dubbo服务时的问题汇总
最近接触新的dubbo项目,项目初始时,测试环境的提供者服务发布较频繁,奈何公司又没有自动发布工具,遂自己在测试环境中搭建了Jenkins用于dubbo服务的发布.由于第一次使用,过程中也遇到了一些问 ...
- Jenkins修改端口号(成功率高)
转载:http://blog.csdn.net/dzh0622/article/details/52470634 Jenkins默认的端口号是8080,修改方法: 1. 打开终端,cd 到Jenkin ...
- Oracle学习笔记(八)
十一.子查询 1.子查询概述 学习子查询的原因 事例:查询工资比SCOTT高的员工信息 思路:1.scott的工资 select sal from emp where ename='SCOTT'; 2 ...
- Centos 7 手把手教你使用YUM方式安装并配置Nginx+php7-fpm+MySQL
需要准备的内容 一台纯净系统的服务器 远程连接服务器的工具 (我这里使用Xshell) 安装nginx 链接上服务器后执行 yum install nginx 这里需要输入y 后回车,开始安装ngi ...