views:

1059

answers:

1

Hi,

I am creating a number of custom controls for a Silverlight 4 project. I have successfully created one control and am wondering if I can define more in the same project and then have all the controls bundled into one .DLL.

Right now, I have the standard files for the first control:

/Resources/icon.png
/themes/generic.xaml 
/CustomControl1.cs
/CustomControl1EventArgs

I am thinking it's not possible, as there can only be one "generic.xaml".

Thanks,

Scott

+3  A: 

Yes you can create multiple controls in the same project, you simply have to place the all the default templates in a single /themes/generic.xaml file. Each controls template is identified by the TargetType. So your generic.xaml file would look something like:-

 <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>

The Silverlight Toolkit chapies do have a neat tool which allows you to place each control template in its own file. The tool dynamically constructs the generic.xaml from the contents of all these files. I really wish they'd blog about it so we could find out how to use it ourselves. Hello any of you Msofties lurky listening in?

AnthonyWJones
Thanks Anthony! I appreciate this. I'd be interested in hearing more about the MS tool, as well.
Scott Davies