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

  1. <Window x:Class="UserGuide.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:UserGuide"
  7. mc:Ignorable="d"
  8. Title="MainWindow" Height="450" Width="800">
  9. <Grid>
  10. <Button Content="Button" HorizontalAlignment="Left" Margin="35,44,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
  11. <Button x:Name="o1" Content="Button" HorizontalAlignment="Left" Margin="274,340,0,0" VerticalAlignment="Top" Width="75"/>
  12. <TextBox x:Name="o2" HorizontalAlignment="Left" Height="23" Margin="387,154,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
  13. <Label x:Name="o3" Content="Label" HorizontalAlignment="Left" Margin="301,63,0,0" VerticalAlignment="Top"/>
  14.  
  15. <Canvas x:Name="can" Background="#33121212" Visibility="Collapsed" />
  16. </Grid>
  17. </Window>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14.  
  15. namespace UserGuide
  16. {
  17. /// <summary>
  18. /// MainWindow.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22.  
  23. List<GuideModel> _elList;
  24. int _currentIndex = ;
  25. PathGeometry borGeometry = new PathGeometry();
  26.  
  27. public MainWindow()
  28. {
  29. InitializeComponent();
  30. _elList = new List<GuideModel>()
  31. {
  32. new GuideModel(){ EL=o1,FBtnDesc="下一步",FDesc="这是Button"},
  33. new GuideModel(){ EL=o2,FBtnDesc="下一步",FDesc="这是Textbox"},
  34. new GuideModel(){ EL=o3,FBtnDesc="关闭",FDesc="这是label"}
  35. };
  36.  
  37. }
  38.  
  39. private void Button_Click(object sender, RoutedEventArgs e)
  40. {
  41. _currentIndex = ;
  42. can.Visibility = Visibility.Visible;
  43. StartGuide();
  44. }
  45.  
  46. private void CreateGuide(GuideModel el)
  47. {
  48.  
  49. can.Visibility = Visibility.Visible;
  50. can.Children.Clear();
  51. Point point = el.EL.TransformToAncestor(Window.GetWindow(el.EL)).Transform(new Point(, ));//获取控件坐标点
  52.  
  53. //设置canvas的clip
  54. RectangleGeometry rg = new RectangleGeometry();
  55. rg.Rect = new Rect(, , this.ActualWidth, this.ActualHeight);
  56. borGeometry = Geometry.Combine(borGeometry, rg, GeometryCombineMode.Union, null);
  57. can.Clip = borGeometry;
  58.  
  59. RectangleGeometry rg1 = new RectangleGeometry();
  60. rg1.Rect = new Rect(point.X - , point.Y - , el.EL.ActualWidth + , el.EL.ActualHeight + );
  61. borGeometry = Geometry.Combine(borGeometry, rg1, GeometryCombineMode.Exclude, null);
  62.  
  63. can.Clip = borGeometry;
  64.  
  65. UC uc = new UC();
  66. uc.SetLbl(el.FDesc);//设置引导描述
  67. uc.SetBtn(el.FBtnDesc);//设置按钮描述
  68. uc.NextFlag += StartGuide;//按钮委托
  69. //设置引导控件位置
  70. uc.SetValue(LeftProperty, point.X + el.EL.ActualWidth);
  71. uc.SetValue(TopProperty, point.Y + el.EL.ActualHeight);
  72. can.Children.Add(uc);
  73.  
  74. _currentIndex++;
  75. }
  76.  
  77. private void StartGuide()
  78. {
  79. if (_currentIndex >= _elList.Count)
  80. {
  81. can.Visibility = Visibility.Collapsed;
  82. return;
  83. }
  84.  
  85. CreateGuide(_elList[_currentIndex]);
  86. }
  87. }
  88.  
  89. public class GuideModel
  90. {
  91. public FrameworkElement EL { get; set; }
  92. public string FDesc { get; set; }
  93. public string FBtnDesc { get; set; }
  94. }
  95.  
  96. }

添加一个引导控件

  1. <UserControl x:Class="UserGuide.UC"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:UserGuide"
  7. mc:Ignorable="d"
  8. Height="200" Width="300">
  9. <Grid Background="Red">
  10. <Label x:Name="lbl" Content="Label" HorizontalAlignment="Left" Margin="65,61,0,0" VerticalAlignment="Top"/>
  11. <Button x:Name="btn" Content="Button" HorizontalAlignment="Left" Margin="172,128,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click" />
  12.  
  13. </Grid>
  14. </UserControl>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14.  
  15. namespace UserGuide
  16. {
  17. /// <summary>
  18. /// UC.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class UC : UserControl
  21. {
  22.  
  23. public delegate void NextFlagHandle();
  24. public NextFlagHandle NextFlag;
  25.  
  26. public UC()
  27. {
  28. InitializeComponent();
  29. }
  30.  
  31. private void Button_Click(object sender, RoutedEventArgs e)
  32. {
  33. NextFlag();
  34. }
  35.  
  36. public void SetLbl(string lblValue)
  37. {
  38. lbl.Content = lblValue;
  39. }
  40. public void SetBtn(string btnValue)
  41. {
  42. btn.Content = btnValue;
  43. }
  44. }
  45. }

自己写着玩玩的,用到项目中肯定需要美化的,基本功能实现了。

WPF 新手引导的更多相关文章

  1. WPF|快速添加新手引导功能(支持MVVM)

    阅读导航 前言 案例一 案例二 案例三(本文介绍的方式) 如何使用? 控件如何开发的? 总结 1. 前言 案例一 站长分享过 眾尋 大佬的一篇 WPF 简易新手引导 一文,新手引导的效果挺不错的,如下 ...

  2. WPF 简易新手引导

    这两天不忙,所以,做了一个简易的新手引导小Demo.因为,不是项目上应用,所以,做的很粗糙,也就是给需要的人,一个思路而已. 新手引导功能的话,就是告诉用户,页面上操作的顺序,第一步要做什么,第二步要 ...

  3. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

  4. MVVM框架从WPF移植到UWP遇到的问题和解决方法

    MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...

  5. MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息

    MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...

  6. MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信

    MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...

  7. MVVM设计模式和WPF中的实现(四)事件绑定

    MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  8. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  9. MVVM模式和在WPF中的实现(二)数据绑定

    MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

随机推荐

  1. Hyberledger-Fabric 1.00 RPC学习(2)尝试建立一个network

    本文参考:http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html 这里我们学习建立第一个Hyperledger Fa ...

  2. spring错误处理 Build path is incomplete. Cannot find class file for org.springframework.aop.Advisor

    Build path is incomplete. Cannot find class file for org.springframework.aop.Advisor 初学spring,记录一下出现 ...

  3. the difference between fopen&open

    [the difference between fopen&open] fopen是C标准API,open是linux系统调用,层次上fopen基于open,在其之上.fopen有缓存,ope ...

  4. du熊的机器人

    [du熊的机器人] Description du熊正在玩一个别人刚送给它的机器人.这个机器人只能在一个棋盘中行走,棋盘的左上角格子为(0, 0),右下角格子为(X, Y). du熊控制这个机器人从棋盘 ...

  5. 第七章 二叉搜索树 07B2-1 插入:算法

  6. PL/SQL 程序

    set serveroutput on

  7. [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] Array and ArrayList

    Array: def x = new String[5] x[0] = "India" x[1] = "USA" x[2] = "Korea" ...

  8. [SoapUI]怎样从应答报文中获取某个字段的值,然后用其改写某个变量

    import com.eviware.soapui.support.GroovyUtils def groovyUtils = new GroovyUtils( context ) def holde ...

  9. web02

    高内聚,低耦合 写what 不写how 我们只关心他是什么,得到什么,我们并不关心怎么去得到的 ,那个细节去怎么得的, 都应该在这个层面上屏蔽掉,要关心的时候在点进去,这样就一层层的结构良好的代码 d ...

  10. Basic4android v3.00 发布

    这次发布的版本主要是增加了快速debuger. 在运行时,可以在IDE 里面随时修改代码,而不需要重新发布应用. 大大提高了开发效率. Basic4android v3.00 is released. ...