WPF中使用USERCONTROL upcode

继续这两篇文章写:

http://daniex.info/wpf-using-usercontrol.html

http://www.codeproject.com/Articles/32825/How-to-Creating-a-WPF-User-Control-using-it-in-a-W

其实UserControl不一定是需要在单独的工程中,在工程内部,也可以像添加一个新class一样添加一个UserControl,这样新UserControl和它的使用者在一个Assembly里面,使用时也就更方便。

在需要使用该UserControl的xaml文件头加上

xmlns:local="clr-namespace:_Name"

其中需要把_Name替换为工程的NameSpace。

在需要放该UserControl的xaml位置加上:

<local:UserControlClassName></local:UserControlClassName>

其中需要将UserControlClassName换为UserControl的类名。

这种方法,很适合将一个很大的.xaml文件划分为几个小的.xaml文件,比较方便模块化,浏览代码页方便。

原文地址:https://www.cnblogs.com/codediscuss/p/3193164.html