简体   繁体   English

在设计时如何引用Silverlight控件库的样式表?

[英]How to reference Silverlight control library's style sheet at design time?

I have a SL4 controls project and I am trying to reference a style sheet within that project from a control which is also inside of the project. 我有一个SL4控件项目,并且试图从该项目内部的控件中引用该项目中的样式表。 The problem is that the the styles do not get applied at design time and I can't see what the controls look like... :( 问题是样式没有在设计时应用,我看不到控件的外观... :(

Is there a way to remedy this? 有没有办法解决这个问题?

Thanks, 谢谢,

Martin 马丁

Edit: 编辑:

The project is called SilverlightControls. 该项目称为SilverlightControls。 Inside of it I have a folder called Resources. 在其中有一个名为Resources的文件夹。 In the folder there is a resource dictionary file called ControlStyles: <ResourceDictionary x:Name="CustomControlStyles"></ResourceDictionary> which defines a few styles. 在该文件夹中,有一个名为ControlStyles的资源字典文件: <ResourceDictionary x:Name="CustomControlStyles"></ResourceDictionary> ,它定义了一些样式。

Within the controls I reference the styles as follows: 在控件中,我引用了以下样式:

<ProfileForm ... Style="{StaticResource ProfileFormStyle}"/>

You'll need to add your resource dictionary as a merged dictionary in each xaml control file. 您需要在每个xaml控制文件中将资源字典添加为合并的字典。 Like this: 像这样:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/SilverlightControls;component/Resources/CustomControlStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

Another way to do this would be using a theme and Custom Controls, but this would mean your custom controls are lookless, and from your question, it doesn't seem like they are. 完成此操作的另一种方法是使用主题和自定义控件,但这将意味着您的自定义控件是无用的,并且从您的问题来看,它们看起来好像不是。 If you want to learn more about themes and custom controls, you can check it out here 如果您想了解有关主题和自定义控件的更多信息,可以在此处查看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM