(2)使用外部程序的自定义类
使用外部程序的自定义类需要设置assembly,如新建一个类型为
Class Library,名为“mumu_customlib”的项目。然后将刚才的Book类添
加到其中。
现在一个解决方案中有两个项目,其中mumu_customnamespace是
一个本地应用程序;mumu_customlib是一个外部程序集。首先在本地应
用程序中添加对mumu_customlib的引用,然后在XAML文件中声明并使
用Book类,如代码4-12所示。
<Window x:Class="mumu_customnamespace.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/ presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:customlib="clr-namespace:mumu_customlib;assembly=mumu_customlib"
Title="Window1" Height="300" Width="300">
<Grid>
<Button FontSize="14">
<customlib:Book Name="葵花宝典" Price="0.1"/>
</Button>
</Grid>
</Window>
代码4-12 引用外部程序集的Book对象
该示例的完整代码详见mumu_customnamespace工程。