利用窗口文件生成WPF自定义控件
Step1.新建窗口文件
在当前项目中新建一个窗口 SelectPathControl
按F7,查找cs代码,并按下图,更改代码
Step2.修改xaml
如下图
Step3. 生成项目
生成后,错误提示消失
Step4.修改代码,重新生成控件
4.1 复制如下代码 SelectPathControl.xaml.cs中
using System.Windows;
using Button = System.Windows.Controls.Button;
using Control = System.Windows.Controls.Control;
using DialogResult = System.Windows.Forms.DialogResult;
using FolderBrowserDialog = System.Windows.Forms.FolderBrowserDialog;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
namespace 无字天书.Controls
{
public enum SelectModeType
{
/// <summary> 选择文件
/// </summary>
SelectFile,
/// <summary> 选择文件夹
/// </summary>
SelectFolder,
/// <summary> 保存文件
/// </summary>
SaveFile
}
/// </summary>
[TemplatePart(Name = "SelectBtn", Type = typeof(Button))]
public partial class SelectPathControl : Control
{
#region 属性
public static readonly DependencyProperty PathProperty =
DependencyProperty.Register("Path", typeof(string), typeof(SelectPathControl), new PropertyMetadata(string.Empty));
/// <summary> 选择的路径
/// </summary>
public