用于创建自定义用户控件的 WPF 教程 [英] WPF tutorial for creating a custom usercontrol

查看:40
本文介绍了用于创建自定义用户控件的 WPF 教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找解释在 WPF 中创建自定义用户控件的教程.

I'm looking for a tutorial that explains creating custom usercontrols in WPF.

我想要一个控件,它结合了一个文本块、一个文本框和一个按钮,用于启动一个通用的文件打开对话框.我已经完成了布局,一切都已连接好.它有效,但它是三个独立的控件.希望有一个教程可以解释如何将其转换为一个用户控件并连接所有内容,以便我可以向我的 WPF 应用程序的其余部分公开控件的某些属性,例如文本框中的文本.

I want to have one control that combines a textblock, a textbox, and a button that launches a common fileopen dialog. I have the layout done and everything wired up. It's works but it's three independent controls. Hopefully there is a tutorial out there that explains how to turn this into one usercontrol and wire up everything so I can expose certain properties of the control, like the text in the textbox, to the rest of my WPF app.

推荐答案

这篇文章看起来不错,可能会有所帮助.

This looks like a good article that might help.

http://www.c-sharpcorner.com/uploadfile/mahesh/user-control-in-wpf/

事实上,看起来他正在做你想做的事情.至于从用户控件外部访问 TextBox 内容,创建一个公共属性,如文章所示.

In fact, it looks like he's doing exactly what you're trying to do. As for accessing the TextBox contents from outside the user control, create a public property as shown in the article.

public string FileName
{
    get { return FBCTextBox.Text; }
    set { FBCTextBox.Text = value; }
}

这篇关于用于创建自定义用户控件的 WPF 教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆