2010-02-04 19 views
3

我正在爲Silverlight 4項目創建一些自定義控件。我已經成功創建了一個控件,並且想知道是否可以在同一個項目中定義更多的控件,然後將所有控件綁定到一個.DLL中。Silverlight 4中的自定義控件需要在單獨的DLL中嗎?

現在,我對第一控制標準文件:

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

我想這是不可能的,因爲只能有一個「generic.xaml」。

感謝,

斯科特

回答

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工具包chapies確實有一個整潔的工具,它允許您將在自己的文件中的每個控件模板。該工具從所有這些文件的內容動態地構造generic.xaml。我真的希望他們能夠發表關於它的博客,所以我們可以找出如何自己使用它。你好,你們中的任何一個?

+0

謝謝安東尼!我很欣賞這個。我也有興趣瞭解有關MS工具的更多信息。 – 2010-02-10 16:57:13

相關問題