我正在为Silverlight 4项目创建许多自定义控件。我已经成功创建了一个控件,我想知道是否可以在同一个项目中定义更多,然后将所有控件捆绑到一个.DLL中。
现在,我有第一个控件的标准文件:
/Resources/icon.png
/themes/generic.xaml
/CustomControl1.cs
/CustomControl1EventArgs
我认为这是不可能的,因为只能有一个“generic.xaml”。
谢谢,
斯科特
答案 0 :(得分:3)
是的,您可以在同一个项目中创建多个控件,只需将所有默认模板放在一个/themes/generic.xaml文件中即可。每个控件模板都由TargetType
标识。所以你的generic.xaml文件看起来像: -
<ResourceDictionary ... blah namespace stuff ...>
<Style TargetType="local:CustomControl1">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomControl1">
<!-- Template for Custom control 1 -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:CustomControl2">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomControl2">
<!-- Template for Custom control 2 -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- and so on -->
</ResourceDictionary>
Silverlight Toolkit的章节确实有一个简洁的工具,允许您将每个控件模板放在自己的文件中。该工具从所有这些文件的内容动态构造generic.xaml。我真的希望他们能够在博客上发表文章,以便我们自己了解如何使用它。你好,Msofties lurky在听吗?