我正在为 Silverlight 4 项目创建许多自定义控件。我已经成功创建了一个控件,我想知道是否可以在同一个项目中定义更多控件,然后将所有控件捆绑到一个 .DLL 中。
现在,我有第一个控件的标准文件:
/Resources/icon.png
/themes/generic.xaml
/CustomControl1.cs
/CustomControl1EventArgs
我认为这是不可能的,因为只能有一个“generic.xaml”。
谢谢,
斯科特
我正在为 Silverlight 4 项目创建许多自定义控件。我已经成功创建了一个控件,我想知道是否可以在同一个项目中定义更多控件,然后将所有控件捆绑到一个 .DLL 中。
现在,我有第一个控件的标准文件:
/Resources/icon.png
/themes/generic.xaml
/CustomControl1.cs
/CustomControl1EventArgs
我认为这是不可能的,因为只能有一个“generic.xaml”。
谢谢,
斯科特
是的,您可以在同一个项目中创建多个控件,您只需将所有默认模板放在一个 /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。我真的希望他们能写博客,这样我们就可以自己了解如何使用它。你好,你们中的任何人都潜伏在听吗?