开发者

Silverlight 4 - Setting design time style of User Controls in controls project?

I have a few user controls that need to be shared between multiple Silverlight 4 project. I am creating a new project that defines those controls in a namespace called [appname].[UI]

I want to create a new Stylesheet for all these controls within the project, however I don't know how to reference the styles at design time (I can reference them via the style="" attribute, but they never get applied)开发者_开发百科.

More over I do know that the application has to "Register" the style sheet as part of its resources. Is there a way to do so from within my UI project?

Am I wrong with my assumptions or is there any work around these issues?


To register, add the <MergedDictionary> tag in your App.xaml <ResourceDictionary> entry. This will allow the application to access your styles, like so:

<Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="YourResourceFile.xaml"/>
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>

Once they are registered, the Style="" attribute should work, but if it doesn't, post the code. It might be an error in the XAML.


The silverlight terminology surrounding styles is a bit confusing. It sounds like when you say stylesheet that you really mean templates. If you want to consistently set public properties on controls (eg. FontSize, Background, etc), you'll want to use a style. But if you want to change the way the control is laid out you're going to want to set a new control template. Modifying the control template is much more powerful for customizing controls but also can be a pain because as far as I know you can only edit templates via the XAML. I think you might be able edit the templates WYSIWYG if you're using Expression Blend.

Overview of differences between Styles and Templates: http://msdn.microsoft.com/en-us/library/cc295273.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜